Search code examples
sqlsql-server-2008ssms-2014

SQL Server 2008: DROP PROCEDURE error


I try to execute this command:

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.njams_test_sql_2.[PROC_CHECK_TRACE_SETTINGS]') AND type in (N'P', N'PC'))
   DROP PROCEDURE dbo.njams_test_sql_2.[PROC_CHECK_TRACE_SETTINGS]
GO

But I'm getting this error:

Msg 166, Level 15, State 1, Line 1
'DROP PROCEDURE' does not allow specifying the database name as a prefix to the object name

What I'm trying to do is to delete all objects in a database, so that the database is empty. I'm using Microsoft SQL Server 2014 Management Studio.


Solution

  • As the error clearly says - you cannot use the database name as a prefix in a DROP PROCEDURE.

    You need to make sure you're connected to the correct database and then you need to execute

    IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.njams_test_sql_2.[PROC_CHECK_TRACE_SETTINGS]') AND type in (N'P', N'PC'))
       DROP PROCEDURE [PROC_CHECK_TRACE_SETTINGS]
    GO