1.添加PRIMARY KEY(主键索引)
语法:ALTER TABLE `表名` ADD PRIMARY KEY ( `列名称` )
mysql>ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` )
2.添加UNIQUE(唯一索引)
语法:ALTER TABLE `表名` ADD UNIQUE ( `列名称`)
mysql>ALTER TABLE `table_name` ADD UNIQUE ( `column`)
3.添加INDEX(普通索引)
语法:ALTER TABLE `表名` ADD INDEX index_name ( `列名称` )
mysql>ALTER TABLE `table_name` ADD INDEX index_name ( `column` )
4.添加FULLTEXT(全文索引)
语法:ALTER TABLE `表名` ADD FULLTEXT ( `列名称`)
mysql>ALTER TABLE `table_name` ADD FULLTEXT ( `column`)
5.添加多列索引
语法:ALTER TABLE `表名` ADD INDEX index_name ( `列名称`, `列名称`, `列名称` )
mysql>ALTER TABLE `table_name` ADD INDEX index_name ( `column1`, `column2`, `column3` )
想要查看表有几个字段设置了索引
语法;SHOW INDEX FROM `表名`
mysql>SHOW INDEX FROM `cccinfo`