AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL CREATE INDEX |
|
SQL > Data Definition Language (DDL) >
Create Index Statement
As mentioned in the Index overview page, a table index helps SQL statements run faster. The syntax for creating an index is: An SQL index is a database object that speeds up data retrieval by enabling the query engine to locate rows without scanning the entire table. You can create a simple index on one column or a composite index spanning multiple columns.
Note that an index can only cover one table. We cannot build an index that covers multiple tables. Let's assume that we have the following table,
Table Customer
and we want to create an index on the column Last_Name, we would type in, If we want to create an index on both City and Country, we would type in, A simple index is an index on a single column, while a composite index is an index on two or more columns. In the examples above, IDX_CUSTOMER_LAST_NAME is a simple index because there is only one column, while IDX_CUSTOMER_LOCATION is a composite index because there are two columns. There is no strict rule on how to name an index. The generally accepted method is to place a prefix, such as "IDX_", before an index name to avoid confusion with other database objects. It is also a good idea to provide information on which table and column(s) the index is used on. Please note that the exact syntax for CREATE INDEX may be different for different databases. You should consult with your database reference manual for the precise syntax. Frequently Asked QuestionsWhat is the purpose of creating an index in SQL?An index improves the speed of data retrieval by allowing the database engine to find rows more quickly without scanning the entire table. This is especially beneficial for large tables with millions of rows. What is the difference between a simple index and a composite index?A simple index is built on a single column (e.g., Can a single SQL index span multiple tables?No. An SQL index can only be created on a single table — it is not possible to build one index that covers multiple tables. Is the CREATE INDEX syntax the same across all databases?No. While the general concept is consistent, the exact syntax for CREATE INDEX may differ between database systems such as MySQL, Oracle, and SQL Server. Always consult your database reference manual for precise syntax. |
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.