/* DROP ALL NON-SYSTEM STORED PROCS */
DECLARE @NAME VARCHAR(200)
DECLARE @SQL VARCHAR(500)
DECLARE @SCHEMA VARCHAR(200)
SELECT @NAME = (SELECT TOP 1 [NAME] FROM SYSOBJECTS WHERE [TYPE] = 'P' AND CATEGORY = 0 ORDER BY [NAME])
SELECT @SCHEMA = (SELECT TOP 1 SCHEMA_NAME(SCHEMA_ID) FROM SYS.PROCEDURES WHERE [NAME] = @NAME)
WHILE @NAME IS NOT NULL
BEGIN
SELECT @SQL = 'DROP PROCEDURE [' + @SCHEMA + '].[' + RTRIM(@NAME) +']'
EXEC (@SQL)
PRINT 'DROPPED PROCEDURE: ' + @NAME
SELECT @NAME = (SELECT TOP 1 [NAME] FROM SYSOBJECTS WHERE [TYPE] = 'P' AND CATEGORY = 0 AND [NAME] > @NAME ORDER BY [NAME])
SELECT @SCHEMA = (SELECT TOP 1 SCHEMA_NAME(SCHEMA_ID) FROM SYS.PROCEDURES WHERE [NAME] = @NAME)
END
GO
/* Drop all tables */
DECLARE @NAME VARCHAR(500)
DECLARE @SQL VARCHAR(300)
SELECT @NAME = (SELECT TOP 1 [NAME] FROM SYSOBJECTS WHERE [TYPE] = 'U' AND CATEGORY = 0 ORDER BY [NAME])
WHILE @NAME IS NOT NULL
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' AND CATEGORY = 0 AND [NAME] > @NAME ORDER BY [NAME])
END
GO
No comments:
Post a Comment