当前位置: 代码迷 >> Sql Server >> 字段为某一特定值,某些字段不能为空的约束如何写
  详细解决方案

字段为某一特定值,某些字段不能为空的约束如何写

热度:121   发布时间:2016-04-27 19:48:53.0
字段为某一特定值,某些字段不能为空的约束怎么写.
字段为某一特定值,某些字段不能为空的约束怎么写.
约束规则可以写吗?


------解决方案--------------------
用触发器实现。

约束规则,根据某列的值而定,需要用触发器实现。
------解决方案--------------------
放在触发器里或用存程过程插入数据时判断
------解决方案--------------------
create trigger 触发器名 on 表名
for insert,delete
as
--inserted表为专用于触发器,记录当前更新或插入的记录
if exists(select * from inserted where class=4 and (start is null or end is null))
rollback tran
  相关解决方案