日期:2014-05-18 浏览次数:20649 次
if object_id('tb','U') is not null drop table tb go create table tb ( prodnum varchar(10), master int ) go if object_id('tr_tb','TR') is not null drop trigger tr_tb go create trigger tr_tb on tb for insert as if exists(select 1 from inserted where prodnum in('04','05','07','08','09','011','012','013','014','016','10','11','19')) and exists(select 1 from inserted where master is null) begin rollback print('prodnum 不允许为 04,05,07,08,09,011,012,013,014,016,10,11,19 其中一个') end go insert into tb values ('04',2) --允许插入 insert into tb values ('06',null) --允许插入 insert into tb values ('08',3) --允许插入 insert into tb values ('09',null) --不允许插入 /* prodnum master ---------- ----------- 04 2 06 NULL 08 3 (3 行受影响) */
------解决方案--------------------