I\'m trying to delete all tables from a database except one, and I end up having the following error:
Cannot delete or update a parent row: a foreign key
This might be useful to someone ending up here from a search. Make sure you're trying to drop a table and not a view.
SET foreign_key_checks = 0; -- Drop tables drop table ... -- Drop views drop view ... SET foreign_key_checks = 1;
SET foreign_key_checks = 0
is to set foreign key checks to off and then SET foreign_key_checks = 1
is to set foreign key checks back on. While the checks are off the tables can be dropped, the checks are then turned back on to keep the integrity of the table structure.