添加、查询和删除唯一性约束

添加:

格式:alter table 表名 add unique(字段名); alter table 表名 add constraint 约束名;

1. alter table newDept1 add  unique(deptno);
-- 注意:没有指定约束名,默认以括号中的首字段名为约束名。

如图所示:

img

2. alter table newDept1 add constraint 唯一性约束 unique(deptno)

如图所示:

img

查询:

格式:show create table 表名; show keys from表名;

1. show create table newDept1;

如图所示:
方式1:

img

方式2:
img

2. show keys from  newDept1;

如图所示:
方式1:
img

方式2:
img

删除:

格式:alter table 表名 drop index 首字段名; alter table 表名 drop index 约束名;

1. alter table  newDept1 drop index 字段名;

如图所示:

img

2. alter table newDept1 drop index 唯一性约束 ;

如图所示:

img