About 626,000 results
Open links in new tab
  1. sql server - How can foreign key constraints be temporarily …

    Right click the table design and go to Relationships and choose the foreign key on the left-side pane and in the right-side pane, set Enforce foreign key constraint to 'Yes' (to enable foreign key constraints) or 'No' (to disable it).

  2. sql server - Temporarily disable all foreign key constraints

    Jul 25, 2012 · Use the built-in sp_msforeachtable stored procedure. To disable all constraints: EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT ALL"; To enable all constraints: EXEC sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL"; To drop all the tables: EXEC sp_msforeachtable "DROP TABLE ?";

  3. SQL SERVER - Disable All the Foreign Key Constraint in Database ...

    Apr 29, 2013 · The below script can be used to drop and recreate the Foreign Key Constraints on a database. In this script we are using a temporary tables to select the existing foreign keys and the respective column name and table name.

  4. sql server - Turn off constraints temporarily (MS SQL ... - Stack Overflow

    Oct 9, 2016 · You can actually disable all database constraints in a single SQL command and the re-enable them calling another single command. See: Can foreign key constraints be temporarily disabled using TSQL?

  5. Disable Foreign Key Constraints in INSERT and UPDATE Statements - SQL ...

    Feb 4, 2025 · You can disable a foreign key constraint during INSERT and UPDATE transactions in SQL Server by using SQL Server Management Studio or Transact-SQL. Use this option if you know that new data will not violate the existing constraint or if the constraint applies only to the data already in the database.

  6. How to Disable All CHECK & Foreign Key Constraints for a Table in SQL ...

    Aug 22, 2019 · You can use the code below to disable all CHECK and foreign key constraints for a specific table in SQL Server. Just replace TableName with the name of the applicable table. ALTER TABLE TableName NOCHECK CONSTRAINT ALL

  7. Drop and Re-Create All Foreign Key Constraints in SQL Server

    Oct 6, 2014 · In some situations you can simply disable and re-enable the constraints, which isn’t all that complex at all. In other cases (say, you want to truncate all tables), you actually need to drop and re-create the constraints.

  8. SQL SERVER – How to Disable and Enable All Constraint for …

    Dec 2, 2014 · The foreachproc is a handy tool, but it doesnt work on SQL AZURE, so I came up with a script to generate the ENABLE/DISABLE constraints for all the database. SELECT ‘ALTER TABLE [‘ + s.name + ‘].[‘ + o.name + ‘] WITH CHECK CHECK CONSTRAINT [‘ + i.name + ‘]’

  9. Disable, enable, drop and recreate SQL Server Foreign Keys

    Nov 19, 2007 · Foreign keys (FK) are designed to maintain referential integrity within your database. When used properly FKs allow you to be sure that your data is intact and there are no orphaned records.

  10. SQL SERVER - Drop All the Foreign Key Constraint in Database

    Apr 11, 2014 · He has written a script which drops all the foreign key constraints and recreates them. He uses temporary tables to select the existing foreign keys and respective column name and table name. Then determine the primary key table and column name and accordingly drop and recreate them.

Refresh