Reputation: 43
I'm working on MySQL. I have three tables like following:
USER PRODUCT RELATIONS
ID NAME ID NAME USER PRODUCT
1 FOO 1 APPLE 1 1
2 BAR 2 CARROT 2 1
1 2
1 2
How can I do to delete on cascade all the rows on table RELATIONS when I delete any row related in USER or PRODUCT?
As I understand, I can't use foreing keys in third table because in both of their columns the values can be repeated
Upvotes: 0
Views: 45
Reputation: 116
Maybe I don't understand why you cannot use foreign keys on the third table, But when you make the User or Product Column on the Relations table foreign keys it will have no effect on duplicates, so adding the On Delete Cascade constraint is enough
Upvotes: 2