mysql disable referential integrity
Asked Answered
D

2

10

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?

Despinadespise answered 31/3, 2012 at 16:59 Comment(1)
thanks a lot, both solutions worked, I just selected the first one as correct, and upvoted both...Despinadespise
J
19

This should work:

SET @@foreign_key_checks = 0;

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

SET @@foreign_key_checks = 1;
Jacquenette answered 31/3, 2012 at 17:2 Comment(0)
H
16
SET FOREIGN_KEY_CHECKS = 0;

DROP TABLE IF EXISTS company;

DROP TABLE IF EXISTS computer;

SET FOREIGN_KEY_CHECKS = 1;
Heliotherapy answered 31/3, 2012 at 17:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.