This blog post is mainly to make some records about the use of some common commands for index operations in MySQL:
show index from table_name;show keys from table_name;
-- 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)
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!