You’re encountering SQL Server error 124 because the procedure you’re attempting to create lacks any executable statements—just empty curly braces `{}` or a blank body. This error prevents the procedure from compiling. The fix requires adding at least one valid statement (e.g., `SELECT`, `CREATE TABLE`, or `BEGIN/END` blocks). No special permissions are needed beyond basic SQL Server access, but verify your connection is active and you’re in a valid schema.
What You'll Need
- A valid SQL Server instance (local or cloud) with write permissions.
- A text editor or SQL Server Management Studio (SSMS) for editing scripts.
- The object name (schema + procedure name) you’re attempting to create.
- At least one executable statement to include in the procedure body.
Step-by-Step
- Open your SQL client:
- For SSMS (desktop), launch the application and sign in with your credentials.
- If using SQL Server Management Studio Online or Azure Data Studio, ensure you’re connected to your database server.
If this step fails, restart SSMS or your SQL client and retry.
- Create a new stored procedure template in a text editor or SSMS:
- In SSMS, right-click the database > Tasks > New Query Editor Window, or use Notepad/LibreOffice to draft the script.
- Enter the following structure, replacing `
` and ` ` with your actual values: ALTER PROCEDURE dbo.AS BEGIN -- INSERT A VALID STATEMENT HERE (e.g., a simple SELECT) SELECT 'This is a test statement'; END
- Validate your syntax before execution:
- Copy the script into SSMS and run it in a query window (not the stored procedure editor) to check for syntax errors.
- If you see errors, fix them first (e.g., missing parentheses, typos).
- Execute the procedure:
- Right-click the database > New Query and paste your script.
- Click Execute (F5 in SSMS).
The error should resolve if the body contains at least one valid statement.
Common Mistakes
- Missing semicolon: After the `BEGIN` block, omit the semicolon. SQL Server syntax requires it *only* after the `END` statement.
- Empty or commented code: Ensure the body isn’t just `{}` or `/* comment */`. Insert a real statement.
- Wrong schema/permission context: Use `ALTER PROCEDURE dbo.
`—not `CREATE PROCEDURE`—unless you’re creating a new object. - Syntax errors in the body: If the statement itself is invalid (e.g., missing columns in a `SELECT`), fix that before the procedure compiles.
Tips
- Use `SELECT 'Hello'` as a minimal test statement. It’s guaranteed to compile without errors.
- For debugging, insert a `PRINT 'Procedure created'` statement to verify the procedure runs post-creation.
- If using SQL Server 2016+, consider `GO` statements between batches (they’re optional but can help in complex scripts).
- Check the
sp_helptextprocedure to inspect your procedure’s body later:EXEC sp_helptext dbo.
Troubleshooting
- Error persists after valid statements:
- Reopen the script and copy-paste the exact template again. Old cached syntax might cause issues.
- Try a simpler statement like `SELECT 1` instead of a complex query.
- Permission denied:
- Run SSMS as an admin or use a user with `db_create_procedures` permission.
- If you’re a guest user, ask your DBA to grant permissions via the database properties.
- Connection timeouts:
- Verify your server name/IP is correct (e.g., `localhost` for local instances).
- Check network connectivity if on remote SQL Server.
- SQL Server Agent or service not running:
- Open Services > Find "SQL Server (MSSQLSERVER)" and restart it.
- For cloud databases, check Azure Portal for service health.
Frequently Asked Questions
Why does SQL Server require a procedure body?
The `CREATE PROCEDURE` (or `ALTER PROCEDURE`) command is a template. SQL Server needs executable code inside `{}` to generate an actual object. Without it, you’re just defining a placeholder.
Is there a way to create an empty procedure?
No. Even a blank `BEGIN ... END` block is treated as empty, so you must include at least a `SELECT` or similar statement. For testing, use `SELECT 'Void'` to avoid clutter.
What if my procedure already exists but fails to run?
Run `EXEC sp_helptext
Why does my procedure compile in one SSMS window but not another?
This often happens due to cached metadata or differences in SSMS versions. Open a fresh query window and copy-paste the script, or rebuild the procedure in a new window using the same steps as above.
Can I use a stored procedure without a body?
Only temporarily—for debugging or testing. Once deployed, every procedure must have executable logic. Tools like `IF EXISTS` checks can help verify objects without running code.
What’s the minimum viable procedure statement?
The simplest valid statement is `SELECT 'Text'`. It’s zero-cost and compiles instantly, making it ideal for testing.
Always back up your database before altering procedures, especially in production environments. For large scripts, consider running `sp_rename` to temporarily disable the procedure during edits if needed.