SQL Server trigger - insert remote record into another table with deletion

I currently have an Item table and an ItemWaste table. Both tables will have some fields, such as: Name, Amount, etc. But there will be another field in the ItemWaste table, which is TimeWasted. I want to automatically insert the DELETED element from the Item table into the ItemWaste table and at the same time insert the delete time in the TimeWasted field.

I had no idea how to do this using a trigger ???

Hope can get some help here ... Rate any feedback ... Thanks ....

+5
source share
2 answers

Of course, not a problem.

AFTER DELETE : - :

CREATE TRIGGER trg_ItemDelete 
ON dbo.Item 
AFTER DELETE 
AS
    INSERT INTO dbo.ItemWaste(Name, Amount, TimeWasted)
        SELECT d.Name, d.Amount, GETDATE()
        FROM Deleted d

! : - . 100 , , - Deleted 100 . , ( ).

+8

, , insert , delete ,

0

All Articles