I've got two tables. When I delete a row in Table1
, I want to set the ID
of that row in all the rows of Table2
to NULL. I've got two relationships on Table1
.
The problem is: I can only set one delete rule: Set NULL. If I try to set the other it fails. But when I try to delete ID 1
from Table1
, this now also fails.
My table data looks like the following:
Table1:
ID Text
1 Hoi
2 Hoi
Table2:
ID ForeignID1 ForeignID2
1 1 2
2 1 1
How do I need to set my constraints, so it sets the Foreign IDs to NULL on Table2
when I delete the row in Table1
?
Best Answer
It is not possible with a constraint. Have a look at Multiple Cascading Actions.
You can use an instead of trigger instead where you do the update in
Table2
before the delete inTable1
.The trigger could look something like this