Created
August 15, 2014 13:47
-
-
Save m4tt1mus/e149313d5637a9da527e to your computer and use it in GitHub Desktop.
Table Killer :)
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
-- 1. Fill out the DbName. | |
-- 2. Run Script | |
-- 3. Select column with scripts | |
-- 4. Copy to another the column | |
-- 5. Paste scripts into new scripts screen and execute | |
DECLARE @Db varchar(100) = 'TechShare-Prosecutor_midland-smoke-test' | |
SELECT 1, 'USE [' + @Db + ']' | |
-- Drops unique and foreign key constraints | |
UNION SELECT 2, 'ALTER TABLE [' + @Db + '].[' + CONSTRAINT_SCHEMA + '].['+ TABLE_NAME | |
+ '] DROP CONSTRAINT [' + [CONSTRAINT_NAME] + ']' | |
FROM [INFORMATION_SCHEMA].[TABLE_CONSTRAINTS] | |
WHERE [CONSTRAINT_CATALOG] = @Db | |
AND [CONSTRAINT_TYPE] != 'PRIMARY KEY' | |
UNION SELECT 3, 'USE [' + @Db + '] DROP TABLE [' + SCHEMA_NAME(schema_id) + '].[' + name + ']' FROM sys.tables | |
UNION SELECT 4, 'USE [' + @Db + '] DROP PROCEDURE [' + SCHEMA_NAME(schema_id) + '].[' + name + ']' FROM sys.procedures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment