資料庫調優教程(六) 索引的相關操作,調優索引

來源:互聯網
上載者:User

資料庫調優教程(六) 索引的相關操作,調優索引
三、           索引


3.      索引的相關操作

上一講我們介紹了索引的作用和種類,這一講我們談談索引的相關操作!

1)    添加索引

前面已經有所介紹,這裡總結一下

添加主鍵索引

create table aaa(id int unsigned primary key auto_increment ,name varchar(32) not null defaul ‘’);alter table 表名 add primary key (列名);

添加普通索引

create index 索引名 on 表 (列名1,列名2);

添加唯一索引

create table ddd(id int primary key auto_increment , name varchar(32) unique);create unique index 索引名  on 表名 (列表..);

添加全文索引

CREATE TABLE articles (       id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,       title VARCHAR(200),       body TEXT,       FULLTEXT (title,body)     )engine=myisam charset utf8;ALTER TABLE articles ADD FULLTEXT (title,body);

2)    查詢索引

show index from emp\G


3)    刪除索引

drop index 索引名稱 on 表名;

4)    修改索引

先刪除,再建立



本講結束,下一講將給大家聊聊索引的代價。





相關文章

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.