1.添加PRIMARY KEY(主键索引):
ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` )
‘table_name‘ 表名
column 字段
将table_name表的column字段设置为主键
2.添加UNIQUE(唯一索引) :
ALTER TABLE `table_name` ADD UNIQUE ( `column` )
3.添加INDEX(普通索引) :
写法一:ALTER TABLE `table_name` ADD INDEX index_name ( `column` )
写法二:CREATE INDEX index_name ON `table_name`(`column1`,`column2`,`column3`)
4.添加FULLTEXT(全文索引) :
ALTER TABLE `table_name` ADD FULLTEXT ( `column`)
5.添加多列索引(联合索引):
写法一:ALTER TABLE `table_name` ADD INDEX index_name ( `column1`, `column2`, `column3` )
写法二:CREATE INDEX index_name ON `table_name`(`column1`,`column2`,`column3`)
6. 查询表索引
SHOW INDEX FROM `table_name`;
7. 删除索引
DROP INDEX index_name ON `table_name`;
原文地址:https://blog.51cto.com/13764714/2410373
时间: 2024-10-01 05:46:02