Microsoft Docs

Overview

This article explains how to modify an existing stored procedure in Microsoft SQL Server. You can change the procedure’s definition, alter its parameters, or update its logic without dropping and recreating it.

Syntax

ALTER PROCEDURE [ schema_name . ] procedure_name 
    [ { @parameter_name [type_schema_name.] data_type 
        [ = default ] 
        [ OUT | OUTPUT ] } [ ,...n ] ]
[ WITH  [ ,...n ] ]
AS 
    { [ BEGIN ] sql_statement [;] [ ...n ] [ END ] }

Parameters

Example: Adding a Parameter

The following example adds a new optional parameter @IsActive to the existing procedure dbo.GetCustomerOrders and updates the query accordingly.

ALTER PROCEDURE dbo.GetCustomerOrders
    @CustomerID INT,
    @StartDate  DATE = NULL,
    @EndDate    DATE = NULL,
    @IsActive   BIT  = 1      -- New parameter
AS
BEGIN
    SET NOCOUNT ON;

    SELECT OrderID, OrderDate, TotalAmount
    FROM Orders
    WHERE CustomerID = @CustomerID
      AND ( @StartDate IS NULL OR OrderDate >= @StartDate )
      AND ( @EndDate   IS NULL OR OrderDate <= @EndDate )
      AND IsActive = @IsActive;
END;

Remarks

See Also