Home  >  Article  >  Backend Development  >  SQL CREATE INDEX statement

SQL CREATE INDEX statement

jacklove
jackloveOriginal
2018-05-08 11:06:191400browse

SQL CREATE INDEX statement is very important in php, this article will explain it.

The CREATE INDEX statement is used to create an index on a table.

Indexes allow database applications to find data faster without reading the entire table.

Index

You can create an index on a table to query data more quickly and efficiently.

Indexes are not visible to users, they can only be used to speed up searches /queries.

Notes:UpdatingA table that contains an index takes more time than updating a table without an index because the index itself also needs to be updated. Therefore, it is ideal to create indexes only on columns (and tables) that are frequently searched.

SQL CREATE INDEX Syntax

Create a simple index on the table. Duplicate values ​​are allowed:

CREATE INDEX index_name
ON table_name (column_name)

Note: "column_name" specifies the column that needs to be indexed.

SQL CREATE UNIQUE INDEX Syntax

Create a unique index on the table. A unique index means that two rows cannot have the same index value.

CREATE UNIQUE INDEX index_name
ON table_name (column_name)

CREATE INDEX Example

This example will create a simple index named "PersonIndex", In the LastName column of the Person table:

CREATE INDEX PersonIndex
ON Person (LastName)

If you want to index the values ​​in a column in descending order, you You can add reserved words after the column name DESC:

CREATE INDEX PersonIndex
ON Person (LastName DESC)

If you want to index To have more than one column, you can list the column names in brackets, separated by commas:

CREATE INDEX PersonIndex
ON Person (LastName, FirstName)

this This article explains the SQL CREATE INDEX statement. For more learning materials, please pay attention to the php Chinese website to view.

Related recommendations:

Related knowledge about SQL DEFAULT constraints

Related knowledge about SQL CHECK constraints

Related knowledge about SQL UNIQUE constraints

The above is the detailed content of SQL CREATE INDEX statement. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn