Home  >  Article  >  Database  >  What is the sql statement to create an index?

What is the sql statement to create an index?

王林
王林Original
2021-06-15 15:12:5712027browse

The sql statement to create an index is [CREATE INDEX indexName ON table_name (column_name)]. This is the most basic index and it has no restrictions.

What is the sql statement to create an index?

#The operating environment of this article: windows10 system, mysql 5.7, thinkpad t480 computer.

The sql statement to create an index is as follows:

The following is the most basic syntax for creating an index, which has no restrictions.

CREATE INDEX indexName ON table_name (column_name)

If it is CHAR, VARCHAR type, length can be less than the actual length of the field; if it is BLOB and TEXT type, length must be specified.

Modify the table structure (add index)

ALTER table tableName ADD INDEX indexName(columnName)

Specify directly when creating the table

CREATE TABLE mytable(  
 ID INT NOT NULL,   
 username VARCHAR(16) NOT NULL,  
 INDEX [indexName] (username(length))  
 );

Related recommendations: mysql video tutorial

The above is the detailed content of What is the sql statement to create an index?. 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