Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete cascade in many to many relation

Status
Not open for further replies.

avihaimar

Programmer
Jul 30, 2003
38
IL
Hey,

I have table A and B that has many to many relation (Table C is the many to many)

I want that when i delete records from A, the records from C and B will also delete.

I set on delete cascade in C table FK (for A and B)

but when i delete records from A it delete only A,C.

Is there any way to delete A,B,C when i delete records from A???

I know that the problem is that this is many to many , so there is an option that some records from B will be delete despite the fact that they have also relation with records that has not deleted, but i dont care to delete those records.

Thank you.
 
table C is a "child" of both A and B

ON DELETE CASCADE only works from parent to child

if you delete a row from A, all related C rows will also be deleted

however, this cannot delete rows in B, because B is not a child of C, it's a parent

r937.com | rudy.ca
 
I know this.

I am asking for any idea that can help me in this issue.

if i delete from A i dont want that the related records will exists in B (There is no option that this records in B are retlated to records in A that were not deleted)
 
It sounds you would want to get rid of the ON DELETE CASCADE and just delete from A and B first (using the technique shown in another recent thread), then delete from C.

If that doesn't make sense, can you show us your table structures ("SHOW CREATE TABLE a" etc.)?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top