GO vs ;

  • This is probably one of those basic questions that I tend to forgot.

    What is the difference between GO and ;

    SELECT * FROM WishIWasAtSqlpass;

    SELECT * FROM IAmAtWork;

    vs

    SELECT * FROM WishIWasAtSqlpass

    GO

    SELECT * FROM IAmAtWork

    GO

  • Here is a thread where that topic was discussed

    http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/b9813ad0-6053-4723-8516-87cf27ebcf35/

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • The semicolon is a statement terminator and can actually have an affect in terms of compilability of code (specifically with reference to Common Table Expressions), and is listed as "will be required in a future version of SQL Server" by Microsoft.

    "GO" is a batch separator, and doesn't actually even get sent to the server. It's just a local command in Management Studio, and you can actually change it from GO to something else if you want to, in the Tools, Options settings in SSMS. That's why it has to be on a line by itself (with the exception of a number being allowed if you want a batch run multiple times.)

    They do similar things in a few instances, but don't have the same function at all as far as SQL Server is concerned.

    Try using GO inside a dynamic SQL statement. You'll get an error, which you won't with a semicolon.

    Try using a semicolon before a Create Table statement. You'll get an error, which you won't with a batch separator.

    Same for a semicolon followed by a number, which will give an error. But a batch separator will run the preceeding batch X times.

    Example:

    PRINT 'X'

    GO 100

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • btw get used on using the statement terminator ';' because it will become mandatory in one of the next versions !

    That will save you time fixing it later on πŸ˜‰

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution πŸ˜€

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • I believe β€˜;’ is an ANSI SQL statement terminator which you can use with other RDBMS as well. The same is not true with β€˜GO’ as its Microsoft’s own implementation for batch termination (it’s also customizable, as per previous posts)

  • Dev @ +91 973 913 6683 (10/11/2011)


    I believe β€˜;’ is an ANSI SQL statement terminator which you can use with other RDBMS as well.

    Oracle uses it too

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" πŸ˜‰

  • Perry Whittle (10/11/2011)


    Dev @ +91 973 913 6683 (10/11/2011)


    I believe β€˜;’ is an ANSI SQL statement terminator which you can use with other RDBMS as well.

    Oracle uses it too

    Since when is Oracle a good reference πŸ˜‰

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution πŸ˜€

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Since when is Oracle a good reference πŸ˜‰

    I am sorry but are you talking about this Oracle :hehe:

    In Classical Antiquity, an oracle was a person or agency considered to be a source of wise counsel or prophetic opinion, predictions or precognition of the future, inspired by the gods. As such it is a form of divination. (Courtesy: Wikipedia)

  • ALZDBA (10/17/2011)


    Perry Whittle (10/11/2011)


    Dev @ +91 973 913 6683 (10/11/2011)


    I believe β€˜;’ is an ANSI SQL statement terminator which you can use with other RDBMS as well.

    Oracle uses it too

    Since when is Oracle a good reference πŸ˜‰

    Dude, i dont want to get into one of your product fanboy wars πŸ˜€

    I merely pointed out that Oracle, which incidentally is one of the largest established RDBMS providers, uses this too πŸ˜‰

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" πŸ˜‰

  • Perry Whittle (10/17/2011)


    ALZDBA (10/17/2011)


    Perry Whittle (10/11/2011)


    Dev @ +91 973 913 6683 (10/11/2011)


    I believe β€˜;’ is an ANSI SQL statement terminator which you can use with other RDBMS as well.

    Oracle uses it too

    Since when is Oracle a good reference πŸ˜‰

    Dude, i dont want to get into one of your product fanboy wars πŸ˜€

    I merely pointed out that Oracle, which incidentally is one of the largest established RDBMS providers, uses this too πŸ˜‰

    No worries, Perry. Just throwing a stick in the hen house. That's why I added the πŸ˜‰ icon.

    As many of us, I also have some responsibilities in that area :hehe:

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution πŸ˜€

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • ANSI standard ; terminator came from some flavors of Fortran as well as SAS (r)

Viewing 11 posts - 1 through 10 (of 10 total)

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