Skip to content

Instantly share code, notes, and snippets.

@hummus
Created May 31, 2013 04:38
Show Gist options
  • Save hummus/5682969 to your computer and use it in GitHub Desktop.
Save hummus/5682969 to your computer and use it in GitHub Desktop.
mysql: quick drop all foreign key constraints
mysql -u $USER -p$PASS -e 'select * from information_schema.TABLE_CONSTRAINTS where CONSTRAINT_TYPE="FOREIGN KEY"' -B | awk '{if (NR!=1) print("ALTER TABLE "$2"."$5" DROP FOREIGN KEY "$3";")}' | mysql -u $USER -p$PASS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment