When is usage of semicolon necessary?

Semicolon is used as a statement terminator in almost all RDBMSs. However the usage of semicolon is optional in SQL Server except for few cases. Here are at least three cases where usage of semicolon is a must

1 At the start of the Common Table Expression (If any statement precedes it)

2 If the procedure name is GO ,to execute it use at the end of GO

Let us create this stored procedure with Batch separator GO

use tempdb


select 10 as number 

Now execute the procedure


Nothing happens

Now execute it with semicolon


The result is 10

3 At the end of Merge statement

Let me know if it is required in any other cases.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s