索引是创建在表上的,对数据库表中一列或多列的值进行排序的一种结构。其作用主要在于提高查询的速度,降低数据库系统的性能开销。

    创建索引

    1. CREATE [UNIQUE] INDEX indexname
    2.     ON tblname (index_col_name,...)
    3. [index_type] [index_options]

    查看索引

    1. SHOW INDEX FROM tblname;

    删除索引

    1. DROP INDEX indexname
    2.    ON tblname;

    示例

    1. 执行以下命令,创建表 test。
    1. CREATE TABLE test (c1 int primary key, c2 VARCHAR(10));
    1. 执行以下命令,创建表 test 的索引。
    1. CREATE INDEX test_index ON test (c1, c2);
    1. 执行以下命令,查看表 test 的索引。
    1. SHOW INDEX FROM test;
    1. 执行以下命令,删除表 test 的索引。
    1. DROP INDEX test_index ON test;