10

I have found some SP(stored procedure) written as,

CREATE PROCEDURE [dbo].[XXX]
(
   -- Parameters
)
BEGIN

--- Actual Work

END

and some as

CREATE PROCEDURE [dbo].[XXX]
(
   -- Parameters
)


--- Actual Work

What makes it difference?

2 Answers 2

13

There is no difference. That is, it's optional.

What matters is the "end of the batch" which is denoted in SQL Server Management Studio by GO

1
  • 1
    BEGIN / END is optional, you can add them anywhere (without any IF, WHILE blocks...). I suggest do not use them in SP because you can add some test selects after (redundant) END and then alter procedure with them by mistake.
    – DiGi
    Jun 11, 2013 at 7:57
5

There is no real difference. Create procedure syntax specifies BEGIN and END as optional. And it makes sense since CREATE PROCEDURE statement cannot be combined with other statements in a single batch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.