Created
January 7, 2013 19:58
-
-
Save stevewithington/4477879 to your computer and use it in GitHub Desktop.
SQL Server Script to delete all FK in the DB and drop any table that starts with XXX
This file contains hidden or 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 @sqlForeignKeys VARCHAR(MAX) | |
SELECT @sqlForeignKeys = ISNULL(@sqlForeignKeys,'') + | |
'ALTER TABLE dbo.[' + OBJECT_NAME(FK.parent_object_id) + '] DROP CONSTRAINT [' + FK.name + '];' + CHAR(10) | |
FROM SYS.FOREIGN_KEYS FK | |
//PRINT(@sqlForeignKeys) | |
EXEC(@sqlForeignKeys) | |
DECLARE @sqlForeignKeys VARCHAR(MAX) | |
SELECT @sqlForeignKeys = ISNULL(@sqlForeignKeys,'') + | |
'DROP TABLE dbo.[' + NAME + '] ;' + CHAR(10) | |
FROM sysobjects | |
where name like 'XXXX%' | |
//PRINT(@sqlForeignKeys) | |
EXEC(@sqlForeignKeys) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment