Introduction:
Here i will show you sql query for how to delete all stored procedure of database with single query
Explanation:
Here i have used cursor to delete all stored procedure of table.You just copy and paste below query to your sql query editor.
USE <database name>
DECLARE @UserStoredProcedure VARCHAR(100)
DECLARE @Command VARCHAR(100)
DECLARE UserStoredProcedureCursor CURSOR SCROLL STATIC READ_ONLY FOR
SELECT
SPECIFIC_NAME
FROM
INFORMATION_SCHEMA.ROUTINES
OPEN UserStoredProcedureCursor
FETCH NEXT FROM UserStoredProcedureCursor
INTO @UserStoredProcedure
WHILE (@@FETCH_STATUS = 0) BEGIN
SET @Command = 'DROP PROCEDURE ' + @UserStoredProcedure
-- display; visual check
SELECT @Command
DECLARE @UserStoredProcedure VARCHAR(100)
DECLARE @Command VARCHAR(100)
DECLARE UserStoredProcedureCursor CURSOR SCROLL STATIC READ_ONLY FOR
SELECT
SPECIFIC_NAME
FROM
INFORMATION_SCHEMA.ROUTINES
OPEN UserStoredProcedureCursor
FETCH NEXT FROM UserStoredProcedureCursor
INTO @UserStoredProcedure
WHILE (@@FETCH_STATUS = 0) BEGIN
SET @Command = 'DROP PROCEDURE ' + @UserStoredProcedure
-- display; visual check
SELECT @Command
-- when you are ready to execute, uncomment below
EXEC (@Command)
FETCH NEXT FROM UserStoredProcedureCursor
INTO @UserStoredProcedure
END
CLOSE UserStoredProcedureCursor
DEALLOCATE UserStoredProcedureCursor
SET NOCOUNT OFF
You just change <database name> to your database name it will delete all stored procedure of your database.
No comments:
Post a Comment