CREATE TRIGGER 名1 ON 数据表
FOR INSERT
AS
if exists(select 1 from inserted tem where exists(select 1 from 数据表 where 物品代码=tem.物品代码 and 检测项目=tem.物品代码 and (小数位数<>tem.小数位数 or 整数位数<>tem.整数位数 or 规格下限>tem.规格下限 or 规格上限<tem.规格上限)))
rollback tran
FOR INSERT
AS
if exists(select 1 from inserted tem where exists(select 1 from 数据表 where 物品代码=tem.物品代码 and 检测项目=tem.物品代码 and (小数位数<>tem.小数位数 or 整数位数<>tem.整数位数 or 规格下限>tem.规格下限 or 规格上限<tem.规格上限)))
rollback tran
FOR INSERT
AS
if Exists(
Select * from inserted a
where Exists(Select * from 数据表 where a.规格下限 between 规格下限 and 规格上限)
or Exists(Select * from 数据表 where a.规格上限 between 规格下限 and 规格上限)
)
Raiserror('有不合法数据!!!',16,1)
Rollback