Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop group of stored procedures by name

I have group of stored procedures with names like 'somename_%'. Are there any way to delete that SP with one query, forexample

DROP PROCEDURE where name like 'somename_%'

.

like image 283
Kate Avatar asked Mar 15 '10 09:03

Kate


2 Answers

This works for MSSQL 2005 +

DECLARE @DropScript varchar(max)
set @DropScript = ''

SELECT @DropScript = @DropScript + 'DROP PROCEDURE [' + schema_name(schema_id)+ '].' + '[' + name + ']
' FROM sys.procedures
where name like 'somename_%'


exec (@DropScript)
like image 59
Martin Smith Avatar answered Oct 31 '22 04:10

Martin Smith


You can generate the DDL by querying the data dictionary. For example, in Oracle:

SELECT 'DROP PROCEDURE "'||owner||'"."'||object_name||'";'
FROM all_procedures
WHERE procedure_name IS NULL
AND lower(object_name) LIKE 'somename_%';
like image 23
Jeffrey Kemp Avatar answered Oct 31 '22 04:10

Jeffrey Kemp