home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 18,512 of 19,505   
   Erland Sommarskog to harish saharan   
   Re: How to disable all constraints   
   23 Nov 11 08:56:13   
   
   0ac041fe   
   From: esquel@sommarskog.se   
      
   harish saharan (harishksaharan@gmail.com) writes:   
   >                          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@sommarskog.se   
      
   Books Online for SQL Server 2005 at   
   http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx   
   Books Online for SQL Server 2000 at   
   http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca