Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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?

share|improve this question

migrated from codereview.stackexchange.com Jun 10 '13 at 16:52

This question came from our site for peer programmer code reviews.

2 Answers 2

up vote 9 down vote accepted

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

share|improve this answer
    
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 '13 at 7:57

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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