Home > Database > Mysql Tutorial > body text

MySQL SQL code example about index operation

黄舟
Release: 2017-03-15 17:21:31
Original
1614 people have browsed it


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

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

3. Delete the index

DROP INDEX index_name ON table_nameALTER TABLE table_name DROP INDEX index_nameALTER TABLE 
table_name DROP PRIMARY KEY
Copy after login

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!

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!