Troubleshooting Guide: Error 2004 – Procedure Already Created with Group Number
Why This Error Happens
This error occurs when attempting to create a numbered procedure (using the ;n syntax, e.g., MyProc;2) with a group number that already exists for that procedure name in the database. SQL Server uses grouped procedures to allow multiple procedures to share a single name while being dropped together, and each group number must be unique within that name set. This typically results from a script re-running without checking for existing group numbers, a deployment pipeline duplicating a CREATE PROCEDURE statement, or legacy T-SQL scripts carried over from older SQL Server versions where numbered procedures were more common.
Step-by-Step Resolution Guide
Step 1: Identify Existing Procedure Group Numbers
- Open SQL Server Management Studio (SSMS) 21 or Azure Data Studio connected to your SQL Server 2025 instance.
- Run the following query to check existing group numbers for the procedure name:
SELECT o.name, o.number
FROM sys.objects o
WHERE o.name = 'YourProcedureName' AND o.type = 'P';
- Note which numbers (1, 2, 3, etc.) are already in use so you can select an unused one.
Step 2: Modify the CREATE PROCEDURE Statement
- Edit your T-SQL script and change the group number suffix to an unused value.
- Example: if
MyProc;2already exists, change your new procedure creation toMyProc;3.
CREATE PROCEDURE MyProc;3
AS
BEGIN
SELECT 1;
END
- Save the script before re-executing it against the target database.
Step 3: Drop and Recreate the Procedure Group (If Appropriate)
- If the duplicate group number was created in error and the old version is no longer needed, drop the entire procedure group rather than incrementing the number:
DROP PROCEDURE MyProc;
- Note that
DROP PROCEDURE MyProc;without a number removes all grouped versions (e.g.,MyProc;1,MyProc;2). - Recreate the procedure(s) cleanly with sequential, non-conflicting group numbers starting from 1.
Step 4: Update Deployment Scripts and Source Control
- Check your DACPAC, SSDT project, or deployment pipeline (Azure DevOps, GitHub Actions) for hardcoded group numbers in
.sqlfiles. - Replace legacy numbered procedures with separate, individually named procedures where possible, since Microsoft has deprecated numbered procedure groups in favor of single-purpose stored procedures.
- Commit the corrected script to version control to prevent the same conflict on the next deployment.
Alternative or Verification Steps
- Verify the fix by re-running the
sys.objectsquery from Step 1 and confirming the new procedure appears with the correct, unique group number and no error is thrown. - As a long-term alternative, avoid numbered procedure groups entirely by refactoring them into distinct, independently named stored procedures (e.g.,
MyProc_Insert,MyProc_Update), which eliminates group number conflicts permanently and aligns with Microsoft’s deprecation guidance.