Posted By

keanu on 07/28/10


Tagged


Versions (?)

暫時性關閉/開啟 SQL Server 的 FK Constraints


 / Published in: SQL
 

URL: http://stackoverflow.com/questions/159038/can-foreign-key-constraints-be-temporarily-disabled-using-tsql

  1. -- disable all constraints
  2. EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
  3.  
  4. -- enable all constraints
  5. exec sp_msforeachtable @command1="print '?'", @command2="ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"

Report this snippet  

You need to login to post a comment.