MySQL 索引的增刪查

2022-05-01 08:12:10 字數 688 閱讀 3505

檢視索引:

> show index from table_name;

> show keys from table_name;

刪除索引:

> drop index index_name from table_name;

> drop index test_index from contents;

建立普通索引:

> create index 索引名稱 on 表名稱 (`列名稱`);

> create index test_index on contents(`title`);

建立唯一索引:

> create unique index 索引名稱 on 表名稱 (列名稱);

> create unique index test_cid on contents(`cid`);

建立主鍵索引:

> create table table_name( [...], primary key(`列的列表`) );

> alter table table_name add primary key(`表的主鍵`);

> alter table contents add primary key(`cid`);

建立多列索引:

> create index 索引名 on 表名(`列名1`,`列名2`,`列名3`, ...);

mysql 索引 增刪查

一 建立 建立單個索引的語法 create index 索引名 on 表名 欄位名 索引名一般是 表名 欄位名 給id建立索引 create index t1 id on t1 id 建立聯合索引的語法 create index 索引名 on 表名 欄位名1,欄位名2 二 刪除 可利用alter t...

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 ...