How to Disable All Constraints in the Database temporarily in SQL Server ?

Published on December 11, 2013 by abundantcode

Filed under SQL Server

Last modified December 11, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 3296 times

There are times when you may want to disable all the constraints in the your SQL Server Database tables when importing the data from the external data source .

How to Disable All Constraints in the Database temporarily in SQL Server ?

Below is a sample query that lets you to quickly disable the constraints like foreign keys , unique keys etc for the database tables.

EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"

Simple isn’t it ?

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

How to Enable or Disable Visual Styles in your VB.NET Winforms Application?

You can enable or Disable the Visual Styles in your VB.NET Winforms Application by following the bel...

How to Perform Inner Join using LINQ in C# ?

Are you looking for the syntax on how to perform inner join using LINQ in C# ? . Below is a sample c...

How to Enable All Constraints back in the Database in SQL Server ?

In one of the articles , we explained How to Disable All Constraints in the Database temporarily in ...