首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

这样如何写

2012-02-23 
这样怎么写当表processpdproduct 字段prodnum内容为04,05,07,08,09,011,012,013,014,016,10,11,19时字段ma

这样怎么写
当表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 行受影响)*/
[解决办法]
探讨
前台判断比较好。能不用触发器就不用触发器。

热点排行