mysql 索引 增刪查

2021-07-13 04:33:45 字數 947 閱讀 3471

一:建立

建立單個索引的語法:create index 索引名 on 表名(欄位名)

索引名一般是:表名_欄位名

給id建立索引:create index t1_id on t1(id);

建立聯合索引的語法:create index 索引名 on 表名(欄位名1,欄位名2)

二:刪除

可利用alter table

或drop index

語句來刪除索引。類似於

create index

語句,drop index

可以在alter table

內部作為一條語句處理,語法如下。

drop index index_name on talbe_name

alter table table_name drop index index_name

alter table table_name drop primary key

其中,前兩條語句是等價的,刪除掉

table_name

中的索引

index_name。

第3條語句只在刪除

primary key

索引時使用,因為乙個表只可能有乙個

primary key

索引,因此不需要指定索引名。如果沒有建立

primary key

索引,但表具有乙個或多個

unique

索引,則

mysql

將刪除第乙個

unique

索引。

如果從表中刪除了某列,則索引會受到影響。對於多列組合的索引,如果刪除其中的某列,則該列也會從索引中刪除。如果刪除組成索引的所有列,則整個索引將被刪除。

三:檢視

mysql> show index from (表名);

MySQL 索引的增刪查

檢視索引 show index from table name show keys from table name 刪除索引 drop index index name from table name drop index test index from contents 建立普通索引 create...

mysql的索引的增刪改查

普通索引index 加速查詢 唯一索引 主鍵索引primary key 加速查詢 約束 不為空 不能重複 唯一索引unique 加速查詢 約束 不能重複 聯合索引 primary key id,name 聯合主鍵索引 unique id,name 聯合唯一索引 index id,name 聯合普通索...

mysql增刪改查效果 mysql增刪改查

檢視所有資料庫 mysql show databases 建立乙個庫ghd並指定字符集為utp8 mysql create database ghd charset utf8 檢視mysql支援的字符集 mysql show char set 建立乙個表,並設定id為主鍵 create table ...