dbTalk Databases Forums  

How to disable all constraints

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss How to disable all constraints in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
harish saharan
 
Posts: n/a

Default How to disable all constraints - 11-23-2011 , 01:51 AM






Dear Sir/Madam
I have a MySQL database with lot of tables .
and I want to disable all the constraints from all the table at the
same time .How can i do it .And after do my work how can i enable all
the constraints again

Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: How to disable all constraints - 11-23-2011 , 02:56 AM






harish saharan (harishksaharan (AT) gmail (DOT) com) writes:
Quote:
I have a MySQL database with lot of tables .
and I want to disable all the constraints from all the table at the
same time .How can i do it .And after do my work how can i enable all
the constraints again
If you have a MySQL database, comp.databases.mysql is over there. This
newsgroup is for SQL Server.

For SQL Server you can do:

SELECT 'ALTER TABLE ' + quotename(s.name) + '.' + quotename(o.name) +
' NOCHECK CONSTRAINT ALL'
FROM sys.objects o
JOIN sys.schemas s ON o.schema_id = s.schema_id
WHERE o.type = 'U'

Run this, copy results and paste into a query window.

To enable constraints again, change NOCHECK to WITH CHECK CHECK. (Yes,
that's two CHECK in a row.)

And, again, this is not a solution for MySQL.



--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.