Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Delete Stored Procedure via SQL
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Delete Stored Procedure via SQL

 Post Reply Post Reply Page  123>
Author
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Topic: Delete Stored Procedure via SQL
    Posted: 04 January 2005 at 10:17am
hi guys,.

does anyone know if you can delete a Stored Procedure using a query. like alter, add a stored procedure. i can't find it anywhere. devguru, didn't help weirdly. or i can't see it.LOL

im making an update script and want to delete all existing SP's then re add the new ones.
Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post Posted: 04 January 2005 at 11:27am
Try 'Drop Procedure name'

Replace name with the stored procedures name.
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 04 January 2005 at 11:35am
If you are using SQL Server (it sounds like you are) you can let enterprise manager do an upgrade script for you and write all of that repetitive code
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 04 January 2005 at 12:34pm
yea is SQL server.

i want a asp page like MS_Server_setup.aspwhich will upgrade my V2 application to V3. add a few fields etc that ok.

i want ed to delete all existing SP's and add the new ones, thanx boRg ill try that.
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 04 January 2005 at 12:52pm
One way to do it is to open up a V2 database in enterprise manager and create a new database diagram.... then using the diagram add all the columns and alter everything that changed between the V2 database and V3... then you just click Generate Update Script on the toolbar or something like that and it will script all the changes for you. At least thats how http://linkmanager.devjunkies.com upgrades work.
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 04 January 2005 at 10:43pm
If your sp's have a certain prefix and you want to make sure all are gone before you re-create them you can also run some query like
Declare @prc varchar(150)
While (Select Count(*) from sysobjects where name Like 'djair_%' and xtype = 'P') > 0
Begin
 Set @prc = (Select 1 [name] from sysobjects where name LIKE 'djair_%' and xtype='P')
 Set @prc = 'Drop Procedure ' + @prc
 Exec(@prc)
END
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 05 January 2005 at 6:29am
cheers michael, thats what i want, Wink

they have a prefix. so that will help.

ill have ago with that. cheers again.
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 05 January 2005 at 4:52pm
hi michael, not sure whats going on here, might be my mistake

do i need to create a stored procedure  to delete the others or would something like this work.

        'delete all stored procedures
        strSQL = "Declare @prc varchar(150) "
        strSQL = strSQL & "While (Select Count(*) from sysobjects where name Like '" & strSPPrefix & "%' and xtype = 'P') > 0 "
        strSQL = strSQL & "Begin "
         strSQL = strSQL & "Set @prc = (Select 1 [name] from sysobjects where name LIKE '" & strSPPrefix & "%' and xtype='P') "
        strSQL = strSQL & "Set @prc = 'Drop Procedure ' + @prc "
        strSQL = strSQL & " Exec(@prc) "
        strSQL = strSQL & "END "


        'Write to the database
        adoCon.Execute(strSQL)

because i have tried the above and when it goes to do it, it just hangs, there are a few Stored procedures but not as many as trhe forum.

thanx in advanced,

its hanging now, been a couple minutes.
Back to Top
 Post Reply Post Reply Page  123>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.