sql 触发器 插入一条记录的同时,更新此插入的一个字段值

2025-01-03 15:46:08
推荐回答(2个)
回答1:

CREATE TRIGGER test_T1 ON dbo.T1
FOR insert
AS
declare @errno int, @errmsg varchar(255)
begin
UPDATE t1
SET t1.c= b+1
FROM t1, inserted
WHERE t1.a= inserted .a
end
return
error:
raiserror @errno @errmsg
rollback transaction

回答2:

CREATE Trigger eTR_T1_INT
On dbo.T1
For Insert
/*编译通过*/
As
Begin
update T1
set c=b+1
from inserted

end