SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


What is a semicolon used for in SQL Server?


What is a semicolon used for in SQL Server?

Author
Message
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85052 Visits: 41074
SQLRNNR (5/10/2013)
Jeff Moden (5/10/2013)
SQLRNNR (5/10/2013)
Not a huge fan of the expected requirement of the semi-colon at the end of each statement.

They do come in handy occasionally to help distinguish the end of some big queries or complex queries.


So does a comment for the next query. :-)


one character or N characters

Sometimes taking the lazy 1 character approach is just so much easier.


The N characters you're talking about are going to be there anyway because I document my code. :-)

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Lynn Pettis
Lynn Pettis
SSC-Dedicated
SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)

Group: General Forum Members
Points: 39011 Visits: 38508
SQLRNNR (5/10/2013)
Jeff Moden (5/10/2013)
SQLRNNR (5/10/2013)
Not a huge fan of the expected requirement of the semi-colon at the end of each statement.

They do come in handy occasionally to help distinguish the end of some big queries or complex queries.


So does a comment for the next query. :-)


one character or N characters

Sometimes taking the lazy 1 character approach is just so much easier.


And the semicolon ENDs the statement where as a comment may not as you could have comments embedded to describe derived tables and their use.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85052 Visits: 41074
I understand what the semi-colon can do so far as ending a statement but it worked just fine before without it before. I don't know what your formatting convention is but I don't need a semi-colon at the end of even the longest of queries to tell me that a new query has started whether the code has any comments or not.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
SQLRNNR
SQLRNNR
SSC-Dedicated
SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)

Group: General Forum Members
Points: 31976 Visits: 18551
Jeff Moden (5/10/2013)
SQLRNNR (5/10/2013)
Jeff Moden (5/10/2013)
SQLRNNR (5/10/2013)
Not a huge fan of the expected requirement of the semi-colon at the end of each statement.

They do come in handy occasionally to help distinguish the end of some big queries or complex queries.


So does a comment for the next query. :-)


one character or N characters

Sometimes taking the lazy 1 character approach is just so much easier.


The N characters you're talking about are going to be there anyway because I document my code. :-)


I know. And I typically document mine (though not as much of a book as yours Wink ) :-D:-D



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


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Lynn Pettis
Lynn Pettis
SSC-Dedicated
SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)

Group: General Forum Members
Points: 39011 Visits: 38508
Jeff Moden (5/10/2013)
I understand what the semi-colon can do so far as ending a statement but it worked just fine before without it before. I don't know what your formatting convention is but I don't need a semi-colon at the end of even the longest of queries to tell me that a new query has started whether the code has any comments or not.


I come from a COBOL environment where (at one time) every sentence had to be terminated by a period. When I started learning SQL (T-SQL) I saw the optional semicolon and just started using it, and I still do today.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
GilaMonster
GilaMonster
SSC Guru
SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)

Group: General Forum Members
Points: 86550 Visits: 45244
Jeff Moden (5/10/2013)
I understand what the semi-colon can do so far as ending a statement but it worked just fine before without it before.


Increasing complexity of the language. SQL is not an LLR-1 language as it is and hence is not that easy to write a parser for, on that jandles all constructs. As more and more gets added, so the parser has to get more and more and more complex. Statement terminators are a definitive way to tell the parser that a statement has finished and another one is about to start.

You said earlier that the parser can always tell if a semi-colon is needed, but it actually can't. Get the WITH wrong in a query that has hints and you get an error saying that a semicolon is required when it isn't. That's a default error for 'Can't figure this out, there's a WITH keyword, maybe they left out a ;' With C++, leaving out a semicolon got you 20 or more errors that never once mentioned a missing semicolon that would start on the line following the missing ;

I don't know what your formatting convention is but I don't need a semi-colon at the end of even the longest of queries to tell me that a new query has started whether the code has any comments or not.


Semicolons aren't for you.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85052 Visits: 41074
Yep. I understand and appreciate all of that. It's a darned shame that it has to come to that.

I kowtowed to the future requirement for semi-colons and started using them religiously even in my posts about a year ago. Us old dogs can learn new tricks if it means keeping the supply of bones coming in. :-D

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
GilaMonster
GilaMonster
SSC Guru
SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)

Group: General Forum Members
Points: 86550 Visits: 45244
To be honest, I doubt they'll be required everywhere anytime in the next 8-10 years. Required in more and more places around new features, yes. Required everywhere, well, we still haven't got rid of old SQL 2000 stuff that's been deprecated for close on 8 years...

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85052 Visits: 41074
Understood. Now, if we could just get them to stop deprecating and removing useful stuff like xp_GetFileDetails and sp_MakeWebTask.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Jamie Ingram-729524
Jamie Ingram-729524
Old Hand
Old Hand (315 reputation)Old Hand (315 reputation)Old Hand (315 reputation)Old Hand (315 reputation)Old Hand (315 reputation)Old Hand (315 reputation)Old Hand (315 reputation)Old Hand (315 reputation)

Group: General Forum Members
Points: 315 Visits: 424
The semicolon character is a statement terminator. It is a part of the ANSI SQL-92 standard, but was never used within Transact-SQL.

Jamie Ingram

We are the pilgrims, master.
We shall go always, a little further.

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