Created
August 19, 2019 16:36
-
-
Save Dillie-O/58b558bcc14fe0830d598018420eaf37 to your computer and use it in GitHub Desktop.
[Drop All Constraints] Drop all constraints in all tables #sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @dropAllConstraints NVARCHAR(MAX) = N''; | |
SELECT @dropAllConstraints += N' | |
ALTER TABLE ' + QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id)) | |
+ '.' + QUOTENAME(OBJECT_NAME(parent_object_id)) + | |
' DROP CONSTRAINT ' + QUOTENAME(name) + ';' | |
FROM sys.foreign_keys; | |
EXEC sp_executesql @dropAllConstraints |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment