1

Possible Duplicate:
When should I use semicolons in SQL Server?

When we are writing a SQL script in T-SQL, should we end each statement with a semi-colon? Does semi-colon work like 'GO' keyword? As of now, I see that it doesn't really matter, but I would like to know which is the best practice?

Community
  • 1
  • 1
rkg
  • 5,559
  • 8
  • 37
  • 50

1 Answers1

3

It's good to get into the habit now because CTE/WITH and MERGE need it, as well as some Service broker stuff as mentioned in the other question. Of course, you could use ;WITH cTE AS ...

C# etc monkeys have been doing it for years.

It won't work with GO because it isn't a keyword. It's a directive for SSMS and other tools to break a larger script into batches.

gbn
  • 422,506
  • 82
  • 585
  • 676
  • As of SQL 2016 the semi-colon will be compulsory: https://learn.microsoft.com/en-us/sql/database-engine/deprecated-database-engine-features-in-sql-server-2016 – maurocam Nov 06 '17 at 16:45
  • @maurocam: It is not compulsory yet: that link shows the not using semi-colon is deprecated, and it will be compulsory in a later version. There is a huge body of code out there that will fail if this is added without some form of flag (trace flag or compatibility level) – gbn Nov 08 '17 at 07:20