【技能库】--mysql indexes 索引操作(195)

来源:互联网 发布:国泰君安快期交易软件 编辑:程序博客网 时间:2024/05/01 05:18

A database index is a data structure that improves the speed of operations in a table. Indexes can be created using one or more columns, providing the basis for both rapid random lookups and efficient ordering of access to records.

ALTER command to add and drop INDEX:

ALTER TABLE tbl_name ADD PRIMARY KEY (column_list): This statement adds a PRIMARY KEY, which means that indexed values must be unique and cannot be NULL.

ALTER TABLE tbl_name ADD UNIQUE index_name (column_list): This statement creates an index for which values must be unique (with the exception of NULL values, which may appear multiple times).

ALTER TABLE tbl_name ADD INDEX index_name (column_list): This adds an ordinary index in which any value may appear more than once.

ALTER TABLE tbl_name ADD FULLTEXT index_name (column_list): This creates a special FULLTEXT index that is used for text-searching purposes.

修改并增加:
mysql> ALTER TABLE testalter_tbl MODIFY i INT NOT NULL;
mysql> ALTER TABLE testalter_tbl ADD PRIMARY KEY (i);

删除主键:
ALTER TABLE testalter_tbl DROP PRIMARY KEY;

删除索引:
ALTER TABLE testalter_tbl DROP INDEX (c);

展示索引:
SHOW INDEX FROM table_name\G

0 0