Skip to content

Instantly share code, notes, and snippets.

@jwliechty
Last active August 29, 2015 14:06
Show Gist options
  • Save jwliechty/7545881b0201ed55324f to your computer and use it in GitHub Desktop.
Save jwliechty/7545881b0201ed55324f to your computer and use it in GitHub Desktop.
Delete all unused foreign keys in 'child' that are supposed to be referenced from 'parent'. (Rows in child belong to rows in parent where child.id = parent.child_id).
DELETE FROM child WHERE id IN
(
SELECT child.id FROM child LEFT JOIN parent ON child.id=parent.child_id WHERE parent.child_id IS NULL
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment