0

I am doing an after insert trigger on a table where I delete the rows that are incorrect, however, I am unable to do this and I can't find the correct syntax anywhere.

From what I understand, the table where the rows will be deleted from is in the FROM clause but I also need to use the inserted table. How do I do this? I know this can be solved using an instead of insert trigger but I really want to know how to do this way.

DELETE 
FROM promotion p, inserted i 
WHERE <conditions>
2
  • 1
    INSERTED is not MySql syntax, have you TAGGED correctly? Commented Dec 8, 2022 at 20:19
  • Just join Inserted on your table (using an explicit join - not your old-school comma join) and delete from the alias of the table i.e. p. Check example D in the docs Commented Dec 8, 2022 at 20:54

1 Answer 1

1

You can try like this:

CREATE TRIGGER myTrigger ON dbo.MyTable
FOR INSERT
AS
SET NOCOUNT ON;
DELETE sometarget
FROM dbo.MyTable AS sometarget
JOIN inserted ON inserted.ID = sometarget.ID
WHERE <conditions>;
GO
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.