W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
該語句用來創(chuàng)建索引。索引是創(chuàng)建在表上的,對(duì)數(shù)據(jù)庫(kù)表中一列或多列的值進(jìn)行排序的一種結(jié)構(gòu)。其作用主要在于提高查詢的速度,降低數(shù)據(jù)庫(kù)系統(tǒng)的性能開銷。
CREATE [UNIQUE] INDEX indexname
?????ON tblname (index_col_name,...)
[index_type] [index_options]
index_type:
USING BTREE
index_options:
index_option [index_option…]
index_option:
GLOBAL | LOCAL
| COMMENT 'string'
| COMPRESSION [=] {NONE | LZ4_1.0 | LZO_1.0 | SNAPPY_1.0 | ZLIB_1.0}
| BLOCK_SIZE [=] size
| STORING(columname_list)
| VISIBLE | INVISIBLE
index_col_name:
colname [(length)] [ASC | DESC]
columname_list:
colname [, colname…]
參數(shù) |
描述 |
---|---|
indexname |
指定要?jiǎng)?chuàng)建的索引名稱。 |
tblname |
指過索引所屬的表名。 |
index_col_name |
指定索引的列名,每個(gè)列名后都支持 ASC(升序),不支持 DESC(降序)。默認(rèn)為升序。 建立索引的排序方式為:首先以 |
index_type |
索引類型,只支持 |
UNIQUE |
指定為唯一索引。 |
index_option |
指定索引選項(xiàng),多個(gè) |
GLOBAL | LOCAL |
指定該索引是全局索引或局部索引,默認(rèn)是 |
COMMENT |
指定注釋。 |
COMPRESSION |
指定壓縮算法。 |
BLOCK_SIZE |
指定微塊大小。 |
STORING |
表示索引表中冗余存儲(chǔ)某些列,以提高系統(tǒng)查詢性能。 |
obclient> CREATE TABLE test (c1 int primary key, c2 VARCHAR(10));
obclient> CREATE INDEX test_index ON test (c1, c2 ASC);
obclient> SHOW INDEX FROM test;
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+-----------+---------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible |
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+-----------+---------------+---------+
| test | 0 | PRIMARY | 1 | c1 | A | NULL | NULL | NULL | | BTREE | available | | YES |
| test | 1 | test_index | 1 | c1 | A | NULL | NULL | NULL | | BTREE | available | | YES |
| test | 1 | test_index | 2 | c2 | A | NULL | NULL | NULL | YES | BTREE | available | | YES |
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+-----------+---------------+---------+
3 rows in set (0.05 sec)
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: