Drop SP without USE <database>

  • Is there a way to drop a stored procedure without first running USE <database> to change the active connection to the database the procedure is in?

    Eg: to drop a table you can do

    DROP TABLE MyDatabase..MyTable

    but to drop a procedure you have to do USE MyDatabase

    DROP PROCEDURE MyProcedure

    and I need to be able to do something like DROP PROCEDURE MyDatabase.MyProcedure

    I can't just create a new procedure to pass in the database and change the connection inside the procedure, I need to be able to drop the procedure without changing the database connection at all.

  • I tried on one of my test boxes, SQL Server 2008 Standard:

    Msg 166, Level 15, State 1, Line 1

    'DROP PROCEDURE' does not allow specifying the database name as a prefix to the object name.

  • how about dynamic SQL?

    execute ('use Perfect1012;drop procedure dbo.pr_fake')

    works for me.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply