stephen.long.1 (10/21/2014)
Excellent question, Sean, and fabulous explanation. It caught me off guard and made me go "WOW" when I read the explanation, because I usually don't like using semi-colons in my T-SQL code (except before a CTE). I had to go look at some recent code I had written using THROW to make sure I had used preceding semi-colons (I had). I will have to add THROW to my mental list of keywords that require a preceding semi-colon.I'm surprised that the T-SQL compiler can't detect THROW as the start of a new statement. I can understand the need for the leading semi-colon for WITH, to differentiate from its usage introducing a table hint (e.g. "SELECT a, b, c FROM TableX WITH (NOLOCK)"), but I don't remember THROW being used anyplace else in T-SQL. Can someone explain why THROW can't just be a reserved word to avoid the need for a semi-colon?
A cte does NOT require it to start with a semicolon. The semicolon is statement terminator not a statement beginninator (nod to Lynn Pettis for that phrase). A cte, just like THROW, requires that the previous statement be terminated with a semicolon.
I usually don't like using semi-colons in my T-SQL code
You should start. It is the ANSI standard and at some point sql server will require it. Notice that all the new features already require it usage.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/