---
title: "“CREATE/ALTER PROCEDURE” must be the first statement in a query batch."  
description: "“CREATE/ALTER PROCEDURE” must be the first statement in a query batch."  
author: "Revati S Misra"  
published: 2023-08-21  
updated: 2023-08-23  
canonical: https://www.mindstick.com/forum/159630/create-alter-procedure-must-be-the-first-statement-in-a-query-batch  
category: "mssql server"  
tags: ["sql server", "sql", "error"]  
reading_time: 1 minute  

---

# “CREATE/ALTER PROCEDURE” must be the first statement in a query batch.

“CREATE/[ALTER](https://www.mindstick.com/forum/159777/how-to-add-a-new-column-to-an-existing-sql-table-using-the-alter-table-statement) [PROCEDURE](https://www.mindstick.com/forum/32/stored-procedure-return-datatype)” [must](https://www.mindstick.com/articles/12978/top-reasons-why-every-magento-ecommerce-store-must-opt-for-mobile-app) be the first statement in a [query](https://www.mindstick.com/blog/202/sub-query-in-sqlserver) batch.

## Replies

### Reply by Aryan Kumar

Yes, the `CREATE` or `ALTER` PROCEDURE statement must be the first statement in a query batch. This is because the `CREATE` or `ALTER` PROCEDURE statement creates or modifies a stored procedure, which is a named set of SQL statements that can be executed as a single unit.

If you try to put the `CREATE` or `ALTER` PROCEDURE statement anywhere else in the query batch, you will get an error.

The following is an example of a query batch that creates a stored procedure:

SQL

```plaintext
CREATE PROCEDURE my_procedure (
  @param1 int,
  @param2 varchar(255)
) AS
BEGIN
  -- Code for the stored procedure goes here.
END;
```

The `CREATE PROCEDURE` statement must be the first statement in the query batch. The `BEGIN` and `END` statements are used to delimit the body of the stored procedure. The `@param1` and `@param2` variables are parameters that can be passed to the stored procedure when it is executed.


---

Original Source: https://www.mindstick.com/forum/159630/create-alter-procedure-must-be-the-first-statement-in-a-query-batch

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
