t-sql约束(一个字段不为空另一个字段也不能为空)
table表有a,b两个字段,需求是加个约束如果a不为空,那么b也不能为空。求教。
[解决办法]
check {a is null and b is null) or (a is not null and b is not null)
[解决办法]
- SQL code
Alter Table tb Add Constraint ab check((a is not null and b is not null) or (a is null))
发布时间: 2012-04-18 15:01:59 作者: rapoo
t-sql约束(一个字段不为空另一个字段也不能为空)
table表有a,b两个字段,需求是加个约束如果a不为空,那么b也不能为空。求教。
[解决办法]
check {a is null and b is null) or (a is not null and b is not null)
[解决办法]
Alter Table tb Add Constraint ab check((a is not null and b is not null) or (a is null))