I’ve read some questions/answers here on Stack but couldn’t find anything like what I need.
Let’s say I have the following table:
col0 col1 col2 col3 col4
---- ---- ---- ---- ----
8 1 a b c
8 2 a b c
8 3 a b c
9 1 a b c
9 2 a b c
And my software does:
INSERT INTO testtable ([col0],[col1],[col2],[col3],[col4])
VALUES ('8','4','a','b','c')
How can I create a trigger like this pseudo-code:
On insert when col1 = '4'
delete existing rows where col0 is the same (8 in this case)
** except for the new row I've just added **
It sounds more appropriate to perform this in an instead of trigger. If the goal is what I assume: when a new row is inserted with col0 = 8, you want to delete all other rows with that same key, yes?
The question is what rule do you want to follow if an insert attempts to add multiple rows with the same col0 value? Imagine the insert statement is: