Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

I'm looking for a way to temporarily turn off all DB's constraints (eg table relationships).

I need to copy (using INSERTs) one DB's tables to another DB. I know I can achieve that by executing commands in the proper order (to not break relationships).

But it would be easier if I could turn off checking constraints temporarily and turn it back on after the operation's finish.

Is this possible?

1 Answer

0 votes
by (40.4k points)

You can try disabling FK and CHECK constraints by using ALTER TABLE

ALTER TABLE foo NOCHECK CONSTRAINT ALL

Or else you can use the below code:

ALTER TABLE foo NOCHECK CONSTRAINT CK_foo_column

Note: Primary keys and unique constraints can not be disabled.

For more, information you can refer to ALTER TABLE. 

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...