Search..

Tuesday, December 15, 2009

How to delete all the stored procedures in a database??

All of a sudden i faced an issue where in i was forced to delete all the stored procedures in a database and recreate them.. if you are facing the same problem do check this out..

Just Run this script and once its executed successfully u'll see no sp in you database..
USE databasename
GO

declare @procName sysname

declare someCursor cursor FOR
SELECT name
FROM
sysobjects
WHERE type='P'AND objectproperty(id,'IsMSShipped')=0

open someCursor
fetch next FROM someCursor INTO @procName
while @@FETCH_STATUS = 0
begin
exec('drop proc ' + @procName)
fetch next FROM someCursor INTO @procName
end

close someCursor
deallocate someCursor
go
but be careful before running this script, always take a backup of the db before deleting all the sp's.

Happy coding...

No comments:

Post a Comment