当表processpdproduct 字段prodnum内容为04,05,07,08,09,011,012,013,014,016,10,11,19时字段master不能为NULL,数据不让插入.
------解决方案--------------------
- SQL code
if object_id('tb','U') is not null drop table tbgocreate table tb( prodnum varchar(10), master int)goif object_id('tr_tb','TR') is not null drop trigger tr_tbgocreate trigger tr_tb on tbfor insertas 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 其中一个') endgoinsert 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 206 NULL08 3(3 行受影响)*/
------解决方案--------------------