How to delete all stored procedures from MSSQL database using cursor
| January 24, 2012 | Posted by Matt under SQL |
Here is a code for deleting all stored procedures in SQL Server database using cursor.
DECLARE @name varchar(500)
DECLARE @sql varchar(max)
SET @sql = ''
DECLARE cur CURSOR
FOR SELECT [name] FROM sys.procedures
OPEN cur
FETCH NEXT FROM cur INTO @name
WHILE @@fetch_status = 0
BEGIN
SET @sql = 'DROP PROC ' + @name
PRINT @sql
EXEC (@sql)
FETCH NEXT FROM cur INTO @name
END
CLOSE cur
DEALLOCATE cur
I am IT professional with over 10 years of experience in computer programming and web development, specializing in Microsoft technologies.



Recent Comments