MYSQL创建索引
方式一
- create 索引類型 索引名 on 表(字段)
- 單值索引
- create index dept_index on tb(dept);
- 唯一索引
- create unique index name_index on tb(name);
- 復合索引
- create index dept_name_index on tb(dept, name);
方式二
- alter table 表名 索引類型 索引名(字段)
- 單值
- alter table tb add index dept_index(dept);
- 唯一
- alter table tb add unique index name_index(name);
- 復合
- alter table tb add index dept_name_index(dept, name);
- DDL 語句不需要 commit; 自動提交
- 如果一個字段是 primary key,該字段默認是主鍵索引
總結