Skip to content

Instantly share code, notes, and snippets.

@Dillie-O
Created August 19, 2019 16:36
Show Gist options
  • Save Dillie-O/58b558bcc14fe0830d598018420eaf37 to your computer and use it in GitHub Desktop.
Save Dillie-O/58b558bcc14fe0830d598018420eaf37 to your computer and use it in GitHub Desktop.
[Drop All Constraints] Drop all constraints in all tables #sql
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