1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| # 创建表时创建索引
# 创建 S 表并以 sname 字段建立普通索引
create table S( sno char(10), sname varchar(20), age int, sex char(2), dept varchar(20), index (sname) );
# 创建 SC 表,并以 sno 和 cno 两字段组合建立名为 uk_sno_cno 多列唯一索引
create table SC( sno char(10), cno char(15), score decimal(4,1), unique index uk_sno_cno(sno,cno) );
# 在已存在的表上创建索引
# 降序普通索引
create index idx_sno on SC(sno desc); alter table SC add index idx_sno (sno desc);
# 唯一索引
create unique index uk_sno on S(sno); alter table S add unique index idx_sno (sno);
|