SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P'ANDcategory = 0ORDERBY [name])
WHILE @nameisnotnull BEGIN SELECT @SQL = 'DROP PROCEDURE [dbo].[' + RTRIM(@name) +']' EXEC (@SQL) PRINT 'Dropped Procedure: ' + @name SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P'ANDcategory = 0AND [name] > @nameORDERBY [name]) END GO
/* Drop all views */ DECLARE @nameVARCHAR(128) DECLARE @SQLVARCHAR(254)
SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'V'ANDcategory = 0ORDERBY [name])
WHILE @nameISNOTNULL BEGIN SELECT @SQL = 'DROP VIEW [dbo].[' + RTRIM(@name) +']' EXEC (@SQL) PRINT 'Dropped View: ' + @name SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'V'ANDcategory = 0AND [name] > @nameORDERBY [name]) END GO
/* Drop all functions */ DECLARE @nameVARCHAR(128) DECLARE @SQLVARCHAR(254)
SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] IN (N'FN', N'IF', N'TF', N'FS', N'FT') ANDcategory = 0ORDERBY [name])
WHILE @nameISNOTNULL BEGIN SELECT @SQL = 'DROP FUNCTION [dbo].[' + RTRIM(@name) +']' EXEC (@SQL) PRINT 'Dropped Function: ' + @name SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] IN (N'FN', N'IF', N'TF', N'FS', N'FT') ANDcategory = 0AND [name] > @nameORDERBY [name]) END GO
/* Drop all Foreign Key constraints */ DECLARE @nameVARCHAR(128) DECLARE @constraintVARCHAR(254) DECLARE @SQLVARCHAR(254)
SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY'ORDERBY TABLE_NAME)
WHILE @nameisnotnull BEGIN SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY'AND TABLE_NAME = @nameORDERBY CONSTRAINT_NAME) WHILE @constraintISNOTNULL BEGIN SELECT @SQL = 'ALTER TABLE [dbo].[' + RTRIM(@name) +'] DROP CONSTRAINT [' + RTRIM(@constraint) +']' EXEC (@SQL) PRINT 'Dropped FK Constraint: ' + @constraint + ' on ' + @name SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY'AND CONSTRAINT_NAME <> @constraintAND TABLE_NAME = @nameORDERBY CONSTRAINT_NAME) END SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY'ORDERBY TABLE_NAME) END GO
/* Drop all Primary Key constraints */ DECLARE @nameVARCHAR(128) DECLARE @constraintVARCHAR(254) DECLARE @SQLVARCHAR(254)
SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY'ORDERBY TABLE_NAME)
WHILE @nameISNOTNULL BEGIN SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY'AND TABLE_NAME = @nameORDERBY CONSTRAINT_NAME) WHILE @constraintisnotnull BEGIN SELECT @SQL = 'ALTER TABLE [dbo].[' + RTRIM(@name) +'] DROP CONSTRAINT [' + RTRIM(@constraint)+']' EXEC (@SQL) PRINT 'Dropped PK Constraint: ' + @constraint + ' on ' + @name SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY'AND CONSTRAINT_NAME <> @constraintAND TABLE_NAME = @nameORDERBY CONSTRAINT_NAME) END SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY'ORDERBY TABLE_NAME) END GO
/* Drop all tables */ DECLARE @nameVARCHAR(128) DECLARE @SQLVARCHAR(254)
SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'U'ANDcategory = 0ORDERBY [name])
WHILE @nameISNOTNULL BEGIN SELECT @SQL = 'DROP TABLE [dbo].[' + RTRIM(@name) +']' EXEC (@SQL) PRINT 'Dropped Table: ' + @name SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'U'ANDcategory = 0AND [name] > @nameORDERBY [name]) END GO