1. 程式人生 > >MySQL建立和刪除索引

MySQL建立和刪除索引

一.新增索引

(1)ALTER TABLE語句

1.PRIMARY  KEY(主鍵索引)
        mysql>ALTER  TABLE  `table_name`  ADD  PRIMARY  KEY (  `column`  ) 
2.UNIQUE(唯一索引)
        mysql>ALTER  TABLE  `table_name`  ADD  UNIQUE (`column` ) 
3.INDEX(普通索引)
        mysql>ALTER  TABLE  `table_name`  ADD  INDEX index_name (  `column`  )
4.FULLTEXT(全文索引)
        mysql>ALTER  TABLE  `table_name`  ADD  FULLTEXT ( `column` )
5.多列索引
        mysql>ALTER  TABLE  `table_name`  ADD  INDEX index_name (  `column1`,  `column2`,  `column3`  )
(2)CREATE INDEX語句
1.UNIQUE(唯一索引)
        mysql>CREATE UNIQUE INDEX index_name ON `table_name` (`column` ) 
2.INDEX(普通索引)
        mysql>CREATE INDEX index_name ON `table_name` (  `column`  )
3.多列索引
        mysql>CREATE INDEX index_name ON `table_name` (  `column1`,  `column2`,  `column3`  )

二.刪除索引

1.PRIMARY  KEY(主鍵索引)
        mysql>ALTER  TABLE  `table_name`  DROP PRIMARY KEY 
3.INDEX(普通索引)或UNIQUE(唯一索引)
        mysql>ALTER  TABLE  `table_name`  DROP INDEX index_name
        mysql>DROP INDEX index_name ON `talbe_name`