我尝试在插入触发器后创建,只要我使用ID在对面的表中插入相同的行,就从表中删除一行
但它不起作用
Create Trigger [dbo].[MeritedDeceased] On [dbo].[Deceased]
After Insert
As
Begin
Delete From dbo.Merited Where dbo.Deceased.ID = dbo.Merited.ID
End
答案 0 :(得分:3)
我认为你的意思是做这样的事情(也许)......
CREATE TRIGGER [dbo].[MeritedDeceased] ON [dbo].[Deceased]
AFTER INSERT
AS
BEGIN
DELETE M
FROM [dbo].[MeritedDeceased] M
INNER JOIN Inserted I
ON I.ID = M.ID
;
END
;
翻译:每次在dbo.Deceased
中插入一行时,请删除dbo.MeritedDeceased
中具有相同(已插入)ID的所有行。
仅供参考,此TRIGGER
不会删除一行,也会删除一起插入的一批行。如果这就是你想要的,那么这应该会有所帮助。