mysql disable referential integrity

opensas picture opensas · Mar 31, 2012 · Viewed 7.7k times · Source

I want to drop all the schemas in a mysql db, and I don't want to be bothered with referential integrity errors

in h2 it's done like this

SET REFERENTIAL_INTEGRITY FALSE;
drop table if exists company;
drop table if exists computer;
SET REFERENTIAL_INTEGRITY TRUE;

How can it be achieved in mysql?

Answer

BluesRockAddict picture BluesRockAddict · Mar 31, 2012

This should work:

SET @@foreign_key_checks = 0;

DROP TABLE IF EXISTS company;
DROP TABLE IF EXISTS computer;

SET @@foreign_key_checks = 1;