alter table 表名
add constraint 约束名 unique (规格说明)
--删除原来的约束需要知道约束名
--用sp_helpconstraint取得约束名
exec sp_helpconstraint '表名'
执行以后constraint_type列应该有一个是check on column 数量
看看constraint_name是什么,然后用以下语句删除
alter table 表名
drop constraint 约束名
--添加新的check约束
alter table 表名 with nocheck
add constraint 约束名 check(数量 between 1 and 1000)
sqlserver中主要有四种约束:
1、实体完整性约束(每一行反应不同的实体)
通过索引,唯一约束。主键约束或标识属性来体现
2、域完整性约束(指给定列的输入有效性)
通过限制数据类型,检查约束,输入格式,外键约束,默认值,非空等体现
3、引用完整性约束(表之间的联系)
通过主外建来建立完整性约束
4、自定义完整性约束(根据用户的需求)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)