如何获取触发器中已删除测试的值?
我需要在 Table1 上的“删除”上放置一个触发器。从 Table1 中删除记录时,我需要在触发器中更新 Table2,但我需要触发器中已删除记录的值。 示例:-
IF OBJECT_ID ('UpdateLog','TR') IS NOT NULL
DROP TRIGGER UpdateLog;
GO
CREATE TRIGGER UpdateLog
ON Table_1
AFTER DELETE
AS
UPDATE Table_2
SET Date1 = getdate()
WHERE (UID from deleted record from Table1)
GO
所以我需要从表 1 中删除的记录的值来更新表 2。如何?
I need to put a trigger on Delete on Table1. On delete of record from Table1, I need to update Table2 in trigger, but i need the value of deleted record in the trigger.
Example:-
IF OBJECT_ID ('UpdateLog','TR') IS NOT NULL
DROP TRIGGER UpdateLog;
GO
CREATE TRIGGER UpdateLog
ON Table_1
AFTER DELETE
AS
UPDATE Table_2
SET Date1 = getdate()
WHERE (UID from deleted record from Table1)
GO
So I need value of deleted record from table1 to update the table2. How?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它应该位于触发器中可用的“已删除”表中。请参阅使用插入和删除的表
请注意,如果您运行删除多条记录可以被删除,并且您的触发器应考虑到“已删除”表包含不止一行。
大致如下:
It should be in the 'deleted' table available in the trigger. See using the inserted and deleted tables
Note that if you run delete mutiple records can be deleted and your trigger should take into account that the 'deleted' table contains more than one row.
Something along the lines of :