For some reason I can't find the exact answer that I need. I searched for at last 20 minutes in here.
I know it's simple. VERY simple. But I can't fire the trigger for some reason..
I have a table with two columns
dbo.HashTags
|__Id_|_name_|
| 1 | Love |
I want to insert the deleted values into another table called dbo.HashTagsArchive
on a DELETE
query.
Example:
DELETE FROM [dbo].[HashTags] WHERE Id=1
After this example I should have the deleted row in dbo.HashTagsArchive
and the row with Id=1
should be deleted in dbo.HashTags
I tried this TRIGGER:
ALTER TRIGGER [dbo].[HashTags_BeforeDelete]
ON [dbo].[HashTags]
FOR DELETE
AS
BEGIN
INSERT INTO HashTagsArchive
( Id,
HashTagId,
delete_date)
SELECT d.Id, m.HashTagId,GETUTCDATE() FROM deleted d
JOIN dbo.HashTags m ON m.Id=d.Id
DELETE FROM dbo.HashTags
WHERE ID IN(SELECT deleted.Id FROM deleted)
END
GO
It's getting Deleted
but no Inserted
row in the HashTagsArchive
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…