34,590
社区成员
发帖
与我相关
我的任务
分享
CREATE TRIGGER [Update_ceshi] ON [dbo].[测试表1]
FOR UPDATE
AS
begin
--1、增加
set nocount on
--2、限定主键不能修改
if update(样品点编号) or update(样品编号)
begin
RAISERROR ('主键不能修改',16, 1)
ROLLBACK TRANSACTION
return
end
update t
set t.A=i.A,t.B=i.B,t.C=i.C
from 测试表2 t , deleted d , inserted i
where t.统一编号=d.样品点编号 and t.样品编号=d.样品编号
--3、增加条件
and d.样品点编号=i.样品点编号 and i.样品编号=d.样品编号
end
----try
CREATE TRIGGER [Update_ceshi] ON [dbo].[测试表1]
FOR UPDATE
AS
begin
update t
set t.A=i.A,t.B=i.B,t.C=i.C
from 测试表2 t , deleted d , inserted i
where t.统一编号=d.样品点编号 and t.样品编号=d.样品编号
end