Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Delete All Stored Procedures

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-04-26 : 16:53:05
Hello,

Is there a command to delete All stored procedures in a Database?

Thanks,
Miguel

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-04-26 : 17:00:45
Here is what I use. Mine searches for specific naming conventions.

It was written for SQL Server 2000, but I believe it works in 2005 too.


USE YourDatabase
GO

SET NOCOUNT ON

DECLARE @objName varchar(80)
DECLARE @objType char(2)
DECLARE grant_perms_on_sps CURSOR FOR
SELECT name, type
FROM SYSOBJECTS
WHERE (
(type = 'P' AND (name LIKE 'usp[_]%' OR name like 'isp[_]%'))
OR
(type = 'FN' AND name LIKE 'udf[_]%')
OR
(type = 'TF' AND name LIKE 'udf[_]%')
OR
(type = 'U')
OR
(type = 'V' AND name LIKE 'v[_]%')
OR
(type = 'TR')
)
AND
uid = 1
AND
status > -1

OPEN grant_perms_on_sps
FETCH NEXT FROM grant_perms_on_sps
INTO @objName, @objType

WHILE @@FETCH_STATUS = 0
BEGIN
IF @objType IN ('TF', 'FN')
EXEC ('DROP FUNCTION dbo.' + @objName)

IF @objType = 'P'
EXEC ('DROP PROC dbo.' + @objName)

IF @objType = 'V'
EXEC ('DROP VIEW dbo.' + @objName)

IF @objType = 'TR'
EXEC ('DROP TRIGGER dbo.' + @objName)

FETCH NEXT FROM grant_perms_on_sps
INTO @objName, @objType
END

CLOSE grant_perms_on_sps
DEALLOCATE grant_perms_on_sps

GO



Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-04-26 : 17:04:55
Run the query in "Results to Text" mode, get the script and run it.


SELECT 'DROP PROC ' + name + char(10) + char(13) + 'GO'
from sysobjects where type = 'p'
order by name



************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-04-26 : 17:12:42
Thank You!
Go to Top of Page
   

- Advertisement -