1、創建表的同時 指定
create table t1(
id int not null,
name char(30) not null,
unique index UniqIdx(id)
)
2、在已經存在的表創建索引
使用ALTER TABLE 語句創建索引
1.執行語句
alter table book add index BkName(bookname(30))
2.show index 查看錶中索引
show index from book
可以看到新增了一個索引
創建唯一索引:
alter table book add index UniqiIdx(bookId)
使用CREATE TABLE 語句創建索引
創建普通索引:
create index BkNameIdx on book(bookname)
創建唯一索引:
create unique index UniqIdx on book(bookId)
刪除索引
使用ALTER TABLE 語句刪除索引
alter table 表名 drop index 索引名
使用DROP INDEX 語句刪除索引
drop index 索引名 on 表名