Created
March 31, 2014 16:33
-
-
Save jeremykdev/9896332 to your computer and use it in GitHub Desktop.
Generate SQL statements to drop all foreign keys in a Microsoft SQL Server database
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
SELECT 'ALTER TABLE ' + QUOTENAME(S.name) + '.' + QUOTENAME(T.name) + ' DROP CONSTRAINT ' + QUOTENAME(FK.name) + ';' | |
FROM sys.foreign_keys AS FK | |
INNER JOIN sys.tables AS T | |
ON ( Fk.parent_object_id = T.object_id ) | |
INNER JOIN sys.schemas AS S | |
ON ( T.schema_id = S.schema_id ) | |
ORDER BY S.name, T.name, FK.name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment