Hugo Kornelis (4/21/2010)
I never understand that habit. The semicolon is a statement terminator, not a statement starter, so the logical place for it is at the end of a statement, not before the next one.
The semicolon has always been part of the Transact SQL syntax, but unlike almost every other language, it was optional.
Can you suggest a language in which it is used as a terminator rather than as a separator? I can't think of one.
I remember the early C++ compilers (the ones which compiled C++ into C and then called a C compiler to get a binary) which were sensitive to the fact that it was not a terminator, but a separator, and didn't like empty statements. So if you wrote a semicolon at the end of the last statement before the terminating brace of a compound statement the parser threw an error. You also got an error if you wrote a semicolon after the closing brace of a compound statement.
Is T-SQL going to break with this tradition and allow semicolon immediately before or immediately after END?
And hence, nobody ever used it. This first changed when the SQL Server 2005 parser required a statement to be terminated in order to recognise WITH as the CTE starter, not as a query hint.
And that was a bad piece of language design. If the parser team were unable conveniently to distinguish the two uses of "WITH" (which suggests either incompetence or unreasonable schedule presure) they should have insisted on a different keyword being used for CTEs, to preserve the language's ability to live without a statement separator.
But in SQL Server 2008, the SQL team went a step further and added "Not using a statement terminator for Transact-SQL statements" to the list of deprecated features. This means that in some future version, you will be required to terminate all statements.
I can't think of a polite way to express my opinion of this MS decision.
So do as I do - start to accustom yourself to terminating all statements with a semicolon today. You'll be thankful later. (And you'll never have to worry about the semicolon before a CTE anymore).
I probably won't do that. I'm old enough that I could happily stop using T-SQL when that change comes in. I'm already getting hell from my wife because I'm trying to work for 8 to 16 weeks a year instead of retiring completely, so doing a couple of weeks on non-database stuff instead of a few months on database when this nonsense kicks in a a few years time might benefit me more from the reduction in nagging I get than it costs me from the loss of fun things to do, so I could stick instead to my beloved declarative (functional, logical, or mathematical) languages which don't need statement separators because each has a decent syntax. And finding 4 weeks work in one of those areas will probably be about as easy as finding 16 weeks as a data management expert.