Index (INDEX) in SQL
SQL index (INDEX) is a special lookup table that database search engines can use to quickly increase the time and performance of data retrieval.
Simply put, an index is a pointer to each value that appears in the indexed table / column. Index in Database has the same meaning as the entries in the Index of a book.
INDEX speeds up SELECT queries containing WHERE or ORDER clauses, but it slows down data entry with UPDATE and INSERT statements. Indexes can be created or deleted without affecting data.
Index types available in SQL:
- Single-Column Index
- Unique Index
- Composite Index
- Implicit Index
To create an index we use the CREATE INDEX command , you can name the index, specify the table, the columns you want to index, and specify the index in ascending or descending order.
CREATE INDEX command
The basic syntax of CREATE INDEX command in SQL is as follows:
CREATE INDEX ten_index ON ten_bang;
SINGLE-COLUMN index
Single-Column Index is created for only 1 column in the table. The basic syntax is as follows:
CREATE INDEX ten_index
ON ten_bang (ten_cot);
UNIQUE index
Unique Index is a unique index, used to increase performance and ensure data integrity. A unique index does not allow any duplicate values to be inserted into the table. Basic syntax is as follows.
CREATE UNIQUE INDEX ten_index
ON ten_bang (ten_cot);
Index COMPOSITE
Composite Index is a combined index for two or more columns in a table. Its basic syntax is as follows:
CREATE INDEX ten_index
ON ten_bang (cot1, cot2);
Note :
- Creating Single-Column Index or Composite Index depends on how often you use the WHERE clause of the query as a filter condition.
- If only one column is used, the best option is the Single-column Index . If two or more columns are used frequently in the WHERE clause as filters, then the Composite Index index is the more optimal option.
IMPLICIT INDEX
Implicit Index is an index that is created automatically by the Database Server when a table is created. Default indexes are automatically created for Primary key constraints and Unique constraints.
DROP INDEX command
When you don't need to use INDEX, you can DROP according to the following syntax:
DROP INDEX ten_index;
You should be careful while deleting an index, because then the performance may be slower or not improved.
When should I avoid using INDEX?
Although INDEX is intended to improve Database performance, sometimes you should avoid using them. Here are some cases you need to consider to decide whether to use INDEX:
- Should not be used in small tables, few records.
- Index should not be used in tables where frequent UPDATE and INSERT operations occur.
- It should not be used for columns that contain a large number of NULL values.
- Index should not be used for columns that are frequently modified.
In the next article, Quantum will discuss with you how to use the ALTER TABLE command in SQL. Have you remembered to it!
Previous lesson: Create a temporary name using ALIAS in SQL
Next lesson: ALTER TABLE statement in SQL
You should read it
- 10 T-SQL Index statements needed with DBA
- Instructions for indexing on the index on the index in Word
- Air quality index - What is AQI?
- What is a crawl? What is index?
- Index in SQL Server
- Limitations of indexes in MongoDB
- What is FPS index? What FPS setting is good for gaming?
- Instructions for using Index function in Excel
May be interested
- Adaptation index (AQ) and strategy to help management leaders changeaq stands for adaptability quotient, which is used to measure the adaptability and flexibility of leaders' strategies to change the environment.
- Instructions for using Index function in Excelindex is a function that returns an array in excel. when using the index function, you get the values in a cell between the column and the row.
- How to reset and re-run the search index on Windows 10by default, windows will use the index when searching to provide faster search results. this article will show you how to reset and re-run the manual search index for accurate search results in windows 10.
- How to Add a Folder to the Windows 7 File Indexthe windows search index is a list of files and folders that are commonly searched. these include the folders in your user directory, and anything in your libraries. adding folders to the index will allow them to be quickly searched, which...
- What is triglyceride? What is the normal triglyceride index?let's find out what triglyceride is by tipsmake.com, how much is the normal triglyceride index so that there are appropriate measures to protect your health!
- Top website see weather and UV indexthese are web services that help you see the uv index and forecast the weather according to the exact time of day.
- Index in SQL Serverthis article explains how to create, rename and delete indexes in sql server.
- How to view UV index on iPhoneyou want to know the uv index where you live or anywhere in the world. you can do it right away without installing 3rd party applications.
- How to Create an Index in Wordthis wikihow teaches you how to create an index page in microsoft word to look up important terms discussed in a document and the pages they appear on. open a microsoft word document. ms word lets you add an index to any document...
- How to change the storage location of Search Index in Windows 10by default, windows will use the index when searching to give you faster search results. this tutorial will show you how to change the storage location of search index data file in windows 10.