Hello.
I want to record changes to a table when a user tries to delete a record. I initially thought that a Delete Trigger would be sufficient, but after searching online, I realize that a BEFORE DELETE statement may be better. I am using sql server 2005. how would the trigger be called from my c# code? or is the trigger raised automatically?
I created a table to store the deleted values each time it is removed from the main table. but when I run it to check my syntax, I have alot of errors. Is what I am proposing even possible?
TRIGGER
I want to record changes to a table when a user tries to delete a record. I initially thought that a Delete Trigger would be sufficient, but after searching online, I realize that a BEFORE DELETE statement may be better. I am using sql server 2005. how would the trigger be called from my c# code? or is the trigger raised automatically?
I created a table to store the deleted values each time it is removed from the main table. but when I run it to check my syntax, I have alot of errors. Is what I am proposing even possible?
Code:
Msg 102, Level 15, State 1, Procedure trg_InventoryDelete, Line 1
Incorrect syntax near 'BEFORE'.
TRIGGER
Code:
CREATE TRIGGER trg_InventoryDelete BEFORE DELETE
ON InventoryResults_Backup
FOR Each row
AS
Declare @userDeleting varchar(50)
Declare @deleteDate smalldatetime
--insert record into audit table
BEGIN
Insert INTO recycleBin (DeletedBy, DateDeleted, InventoryID, Bldg, equipLoc, fk_location, equipment, brand, roomno, floorno,dept,deptno, modelno,serialno,comments, dateInserted)
SELECT @userDeleting, @deleteDate, InventoryID, Bldg, equipLoc, fk_location, equipment, brand, roomno, floorno,dept,deptno, modelno,serialno,comments, dateInserted FROM InventoryResults_Backup
RETURN
END