GoGoAllen
GoGoAllen

Reputation: 117

MySQL ON DELETE CASCADE set but doesn't delete rows from other tables

In my database there are 3 tables of importance: Jobs, Login and Staff. Jobs acts as a linking table, containing both the LoginID & StaffID. I have setup cascading via PHPMyAdmin, like so: enter image description here

However, when I delete a row from the Jobs table, it ONLY deletes from the jobs table and not from corresponding rows from the jobs and login table. What is the reason for this? Thanks.

Upvotes: 0

Views: 896

Answers (1)

Sami Kuhmonen
Sami Kuhmonen

Reputation: 31153

The cascading goes the other way. When you say in jobs table that it refers to login and staff and want to cascade deletes it means that when you delete an item in login or staff the deletion will cascade into jobs table and all rows referring to that row in login or staff will also be deleted.

So in your case jobs is the child table and login/staff are parents. You can't cascade from jobs to login and staff because that would go from child to parent.

Upvotes: 1

Related Questions