As the title states, I'm trying to use a trigger to update a value in Table2 when a row gets deleted from Table1. My code looks like this:
CREATE TRIGGER TRG_Table1_DEL
ON Table1
FOR DELETE
AS
UPDATE Table2 SET
FK_Table1ID = NULL
WHERE FK_Table1ID = (SELECT Table1ID FROM DELETED)
- The first error I get is with the UPDATE command and that states: "Incorrect syntax near 'UPDATE'. Expecting EXTERNAL.
- The second error is with the DELETED table that I'm trying to access. This states "Invalid object name 'DELETED'.
Overall, I'm just trying to mimic a constraint that sets the column to null (ON DELETE SET NULL). I'm doing this because I got an error saying I might cause multiple cycles or cascade paths when trying to add the constraint.
For my code, I based it off this answer.