Home > Database > Mysql Tutorial > body text

What is the sql statement to create an index?

王林
Release: 2021-06-15 15:12:57
Original
12073 people have browsed it

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)
Copy after login

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)
Copy after login

Specify directly when creating the table

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!