mysql——索引

來源:互聯網
上載者:User

標籤:索引增刪改查、索引類型、索引策略、索引最佳化

一、索引的簡單操作(增刪改查)

建立索引

CREATE [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name

[USING index_type]

ON table_name (index_col_name,...)

[UNIQUE|FULLTEXT|SPATIAL]:表示建立索引的類型,分別表示唯一索引、全文索引、空間索引;

[USING index_type]:表示索引的類型,索引類型有BTREE索引和HASH索引。

儲存引擎為MyISAM和INNODB的表中只能使用BTREE;

儲存引擎為MEMORY和heap的表中可以使用BTREE索引和HASH索引

注意:另一種建立索引文法

ALTER TABLE table_name ADD [UNIQUE|FULLTEXT|SPATIAL] INDEX [index_name] [index_type] (index_col_name,...)

查看索引

SHOW INDEX FROM table_name

650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />

刪除索引

--刪除指定表中指定名稱的索引

ALTER TABLE table_name DROP INDEX index_name;

修改索引

在mysql中沒有提供修改索引的指令,一般情況下,直接刪除原索引,重建立立同名索引即可。

舉例:增刪改查索引:在那張表上執行add/drop那個索引

//添加索引

CREATE UNIQUE index index_prizecide on bsy_prizeinfo(prizecode);

//查看索引

show index from bsy_prizeinfo;

//刪除索引

alter table bsy_prizeinfo drop index index_prizecode

//添加索引

alter table bsy_prizeinfo add UNIQUE index index_prizecode (prizecode);

二、索引類型


mysql——索引

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.