What is a semicolon used for in SQL Server?

  • 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
  • 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. 😀

    --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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • 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
  • 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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • 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.

Viewing 5 posts - 16 through 19 (of 19 total)

You must be logged in to reply to this topic. Login to reply