Reputation:
I have a table for example called Updates
Update_ID | Time
and another table called Announce_Updates
Announce_ID | Update_ID
They all have cascade on delete but i can think of some moments when I switched off foreign key check and forgot to reactivate. During that moment, I may have deleted some data on the Updates
table which didn't auto delete on the Announce_Updates
table.
I realized something was wrong when the total count of Update_ID
in Announce_Updates
is greater than that of the main Updates
table itself.
Is there a way to fix this ?
Best regards.
Upvotes: 1
Views: 1267
Reputation: 22646
If there are orphaned Announce_Updates
records you can delete any which don't have a matching Update
:
DELETE FROM Announce_Updates WHERE Update_ID NOT IN (SELECT Update_ID FROM Updates)
As always make sure you back up the database before running any queries that some guy on the internet told you to.
Upvotes: 5