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

來源:互聯網
上載者:User

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


3.      索引的相關操作

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

1)    添加索引

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

添加主鍵索引

[plain] view plaincopy
  1. create table aaa  
  2. (id int unsigned primary key auto_increment ,  
  3. name varchar(32) not null defaul ‘’);  
  4.   
  5. alter table 表名 add primary key (列名);  

添加普通索引

[plain] view plaincopy
  1. create index 索引名 on 表 (列名1,列名2);  

添加唯一索引

[plain] view plaincopy
  1. create table ddd(id int primary key auto_increment , name varchar(32) unique);  
  2.   
  3. create unique index 索引名  on 表名 (列表..);  

添加全文索引

[plain] view plaincopy
  1. CREATE TABLE articles (  
  2.        id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,  
  3.        title VARCHAR(200),  
  4.        body TEXT,  
  5.        FULLTEXT (title,body)  
  6.      )engine=myisam charset utf8;  
  7.   
  8. ALTER TABLE articles ADD FULLTEXT (title,body);  

2)    查詢索引

[plain] view plaincopy
  1. show index from emp\G  


3)    刪除索引

[plain] view plaincopy
  1. 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.