How do I disable
FOREIGN KEY checking for the time of database schema migration?
Currently I found engine-based commands like:
SET CONSTRAINTS ALL DEFERRED;
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all";
SET FOREIGN_KEY_CHECKS = 0;
SET REFERENTIAL_INTEGRITY FALSE;
SET INTEGRITY FOR table OFF;
- SQLite 3.7.16:
PRAGMA foreign_keys = false;
- Oracle 11g seems to have no such command at all
Syntax significantly differ, in case of MSSQL I'm unable to recover previously disabled constraints (if any).
I look for possibly database-independent solution, or at least commands working for whole database of single engine. We can assume there is no constraint violation at the end of migration. Migration will be conducted in a transation.
FOREIGN KEYconstraints only or all kinds of constraints?