------解决方案-------------------- 典型的用触发器来实现
------解决方案-------------------- create trigger tri_tbname_ins on tbname instead of insert as begin if exists(select 1 from inserted i where exists(select 1 from tb where rodNo=i.rodNo and machineNo=i.machineNo)) begin insert tb select * from inserted i where exists(select 1 from tb where rodNo=i.rodNo and machineNo=i.machineNo) end end
------解决方案--------------------
------解决方案--------------------
SQL code
CREATE TRIGGER tri_insert
ON tb
INSTEAD OF INSERT
AS
BEGIN
IF EXISTS (SELECT 1
FROM inserted i,
tb t
WHERE i.rodno = t.rodno
AND i.machineno <> t.machineno)
BEGIN
rasieerror ( '插入失败!插入数据不符合要求' ,16,1 )
END
END
------解决方案--------------------
SQL code
CREATE TRIGGER tri_insert
ON tb
INSTEAD OF INSERT
AS
BEGIN
IF EXISTS (SELECT 1
FROM inserted i,
tb t
WHERE i.rodno = t.rodno
AND i.machineno <> t.machineno)
BEGIN
RAISERROR( '插入失败!插入数据不符合要求' ,16,1 )
END
END