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))