Skip to content

Instantly share code, notes, and snippets.

@m4tt1mus
Created August 15, 2014 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m4tt1mus/e149313d5637a9da527e to your computer and use it in GitHub Desktop.
Save m4tt1mus/e149313d5637a9da527e to your computer and use it in GitHub Desktop.
Table Killer :)
-- 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