赞
踩
接上,现有两张表,department和employee
1、为department的manager添加唯一性约束,保证manager列中不出现重复值(unique_manager是随便设置的约束名称)
alter table department
add constraint unique_manager unique(manager);
关于唯一性约束的各种用法UNIQUE使用
2、将George换成Army
update department
set manager='Army'
where manager='George';
update employee
set name='Army'
where name='George';
3、为department的manager添加非空约束,保证不出现空值
alter table department
alter column manager set not null;
各种约束的添加方式不同,详见添加primary key,not null,unique,default约束
4、限制department的所有budget>100000
alter table department
add constraint check_budget check(budget>100000);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。