views:

19

answers:

1

Hi,

I want to drop a lot of SPs from my SQL Server database. However, I want to write "Delete all procedures except those which contain a certain string in their name".

How can I do this? I am using SQL Server 2008 R2.

Thank

+1  A: 

What about:

SELECT 'DROP PROCEDURE ' + name
FROM    sysobjects WHERE xtype = 'U' AND
        name LIKE 'usp_%'   -- Here you'll define your criteria

After running this, you just need to execute this command output.

Rubens Farias
Thanks! This brings another important consideration - is it possible to see what a query will return/delete but not actually execute it? I think this was covered in the SQL Server MVP Deep Dives book. Thanks.
dotnetdev
@dotnetdev - You could accomplish this by executing the query within a transaction, but then rolling it back after you analyze the results.
Randy Minder
I see. How do I execute the command output? Apologies for the noob like questions.
dotnetdev
Run this, copy the output into an input window, and then execute THAT. This is a SELECT that generates SQL that you can manually run.
Joe

related questions