Enable or Disable all contraints on a MSSQL database

Do you have problems updating a MSSQL table or removing data from it? This is how you can disable or enable all constrains withing a MSSQL database.

  • Open an QueryAnalyzer window and make a connection with your MSSQL database.

  • To disable all constrains you can execute the following statement:

EXEC sp_MSforeachtable 'alter table ? nocheck constraint all'
  • To enable them back you can use:
EXEC sp_MSforeachtable 'alter table ? check constraint all'


0 Comments: