Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Views


Views

Author
Message
Paul White
Paul White
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10338 Visits: 11350
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.

This is one of those (perhaps irrational) things that bothers me too - it makes my brain jolt every time I see that ;WITH construction used. On the other hand, I dislike column lists prefixed with a comma (though I do see why people do that) as well, so maybe it is just me.



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Trey Staker
Trey Staker
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1200 Visits: 2788
Paul White NZ (4/21/2010)
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.

This is one of those (perhaps irrational) things that bothers me too - it makes my brain jolt every time I see that ;WITH construction used. On the other hand, I dislike column lists prefixed with a comma (though I do see why people do that) as well, so maybe it is just me.


I'm on the fence with the comma prefix. I definately have been using the ; at the end of the code block althought It still isn't a habbit and sometimes I forget to do it.; (lol)

---------------------------------------------------------------------
Use Full Links:
KB Article from Microsoft on how to ask a question on a Forum
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21063 Visits: 18258
Paul White NZ (4/21/2010)
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.

This is one of those (perhaps irrational) things that bothers me too - it makes my brain jolt every time I see that ;WITH construction used. On the other hand, I dislike column lists prefixed with a comma (though I do see why people do that) as well, so maybe it is just me.


I'm one who likes to have the comma in front of the column in a list. I do it for ease of commenting out a line if I decide that column should not be included without having to comment out a comma somewhere else. Though - if people were consistent with their commas it wouldn't matter too much and things would line up more neatly.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

mthurber
mthurber
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 909
The question is misleadingly worded. A view definition can contain a CTE, but the CTE is not "part of" the SELECT statement. The CTE can contain its own SELECT statement, and can precede the defining SELECT statement of the view.
ChiragNS
ChiragNS
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2409 Visits: 1865
learnt something new.

"Keep Trying"
TomThomson
TomThomson
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10688 Visits: 11991
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.

Tom

Hugo Kornelis
Hugo Kornelis
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8317 Visits: 11539
Tom.Thomson (7/27/2010)
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?


Yes. The semicolon is a terminator in T-SQL, not a seperator. This is valid code:
IF @Var = 1
BEGIN;
PRINT 'It is 1';
END;
ELSE
BEGIN;
PRINT 'It is not 1';
END;


There is no semicolon after IF @Var = 1 or after ELSE because they need a statement (or a BEGIN END block) to be complete.

There is one annoying exception - in a TRY CATCH block, you get an error when you terminate END TRY with a semicolon. Crying

I don't know enough about C++ to comment about the terminator / seperator difference, so I'll just take your word for it.

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.

Only they could not use anything but WITH for the CTE start, because that is how a CTE is defined in the ANSI standard for SQL. And they could not change the use of WITH for hints either, cause that would break existing code.


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
kapil_kk
kapil_kk
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2417 Visits: 2763
Nice and clean question..
Good discussion :-P

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
manik_anu
manik_anu
Old Hand
Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)

Group: General Forum Members
Points: 374 Visits: 300
nice question.... Easy understandable about both view and CTE....






Manik
**********

Manik
You cannot get to the top by sitting on your bottom.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search