SQL Database Engine Documentation

Deleting Stored Procedures

This document explains how to remove stored procedures from your SQL Server database. Stored procedures are precompiled SQL statements that can be executed repeatedly. While useful, they may need to be deleted if they are obsolete, contain errors, or are no longer required.

Using the `DROP PROCEDURE` Statement

The primary method for deleting a stored procedure is by using the `DROP PROCEDURE` statement in SQL. This statement removes the stored procedure definition and its associated metadata from the database.

Syntax:

DROP PROCEDURE [ IF EXISTS ] <schema_name>.<procedure_name>;

Parameters:

Example 1: Dropping a specific stored procedure

DROP PROCEDURE dbo.usp_UpdateCustomerAddress;

Example 2: Dropping a stored procedure if it exists

DROP PROCEDURE IF EXISTS Sales.usp_CalculateMonthlySales;
Tip: It's a good practice to use IF EXISTS, especially in scripts that might be run multiple times or in different environments, to avoid unexpected errors.

Permissions Required

To drop a stored procedure, you typically need one of the following permissions:

Considerations Before Deleting

Before executing a DROP PROCEDURE statement, consider the following:

Important: Dropping a stored procedure is a permanent action. Once dropped, the procedure cannot be recovered without restoring from a backup.

Using SQL Server Management Studio (SSMS)

You can also delete stored procedures using the graphical interface of SQL Server Management Studio (SSMS):

  1. Connect to your SQL Server instance.
  2. Navigate to your database in the Object Explorer.
  3. Expand the Programmability folder, then expand the Stored Procedures folder.
  4. Right-click on the stored procedure you wish to delete.
  5. Select Delete from the context menu.
  6. A confirmation dialog box will appear. Review the details and click OK to proceed with the deletion.

SSMS will generate and execute the corresponding DROP PROCEDURE statement for you.