Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 9th, 2004, 09:34 AM
Registered User
 
Join Date: Feb 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Way to drop all stored procs from 2k DB?

Hi all,

does anyone know of an easy way to drop all the user stored procedures from a sql2k db in one go?

cheers,
kenny

 
Old February 9th, 2004, 10:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

I am just rushing home at the end of the day, so let me give you a short explanation on how to go about. Sorry, if I haven't given you the entire explanation on how to do it.

The following query will give you all the Stored Procedures.
You can loop through them using WHILE construct and drop them once by one. Here you go,

select a.name from sysobjects a, sysusers b, master..syslogins c where b.suid=c.suid and a.uid=b.uid and c.loginname="<USER_NAME>" and a.type="P"

<USER_NAME> is what the USER you meant. First run this Query carefully and check if the SPs listed are all the User SPs. Then go on to drop them.

Really sorry if I have not given you enough information.

May be some one got a better answer.

Cheers!!!

-Vijay G
 
Old February 9th, 2004, 12:28 PM
Registered User
 
Join Date: Feb 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for that, will have a go & see what happens.
Will base it around...

SELECT name FROM sysobjects WHERE type = 'P' And category = 0

...as i want to drop all non-system procs.

Thanks again,
Kenny


 
Old February 9th, 2004, 12:49 PM
Registered User
 
Join Date: Feb 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ended up with this which seems to work...

/* Drop all non-system stored procs */

declare @name varchar(128)
declare @SQL varchar(254)


SELECT @name = (select top 1 name FROM sysobjects WHERE type = 'P' And category = 0 order by name)
while @name is not null
begin

select @SQL = 'drop procedure [dbo].[' + rtrim(@name) +']'
exec (@SQL)

print 'Dropped :' + @name

SELECT @name = (select top 1 name FROM sysobjects WHERE type = 'P' And category = 0 and name > @name)
end

go


 
Old February 11th, 2004, 06:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes, you are right Kenny. I got it the way you wanted to delete SPs based on USERNAME/LOGINNAME.

Cheers,

-Vijay G
 
Old July 20th, 2007, 10:41 AM
Registered User
 
Join Date: Jul 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This works a bit better (notice I added an order by name)

/* Drop all non-system stored procs */

declare @name varchar(128)
declare @SQL varchar(254)


SELECT @name = (select top 1 name FROM sysobjects WHERE type = 'P' And category = 0 order by name)
while @name is not null
begin

select @SQL = 'drop procedure [dbo].[' + rtrim(@name) +']'
exec (@SQL)

print 'Dropped :' + @name

SELECT @name = (select top 1 name FROM sysobjects WHERE type = 'P' And category = 0 and name > @name order by name)
end

go

 
Old July 23rd, 2007, 08:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Nice to see someone look into it after 3 and half year ;)

cheers.

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Stored procs with ASP tdaustin Classic ASP Databases 4 June 17th, 2008 01:20 AM
O/R mappers vs stored procs rocco50 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 13 June 9th, 2007 07:49 AM
undocumented stored procs priyaram SQL Server 2005 0 February 21st, 2007 12:24 PM
Informix stored procs from ADO tomRA Access 0 October 28th, 2004 09:45 AM
Transactions in C#, not stored procs organicglenn BOOK: ASP.NET Website Programming Problem-Design-Solution 6 October 10th, 2004 09:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.