Home  >  Article  >  Database  >  MySQL SQL code example about index operation

MySQL SQL code example about index operation

黄舟
黄舟Original
2017-03-15 17:21:311594browse


This blog post is mainly to make some records about the use of some common commands for index operations in MySQL:

1. View the index of a table

show index from table_name;show keys from table_name;

2. Create an index

-- index_name可以省略, 创建普通索引ALTER TABLE table_name ADD INDEX index_name (column_list,column_list2 )
-- 创建唯一索引ALTER TABLE table_name ADD UNIQUE (column_list)
-- 创建主键索引ALTER TABLE table_name ADD PRIMARY KEY (column_list)

--或则是以下两种,只能作用于普通索引和唯一索引CREATE INDEX index_name ON 
table_name (column_list)CREATE UNIQUE INDEX index_name ON table_name (column_list)

3. Delete the index

DROP INDEX index_name ON table_nameALTER TABLE table_name DROP INDEX index_nameALTER TABLE 
table_name DROP PRIMARY KEY

The above is the detailed content of MySQL SQL code example about index operation. 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