What is the result ? (SQLServer 2005)

  • In SSMS, if you write the statement in 1 line, you get a syntax error:

    print 'Hey what''s going on ?';GO 10

    But changing it to 2 lines works fine:

    print 'Hey what''s going on ?';

    GO 10

    Can somebody explain why GO preceded by a ; gives error?

  • re: why GO has to be on its own line.

    From the BOL help screen....

    GO is not a Transact-SQL statement; it is a command recognized by the sqlcmd and osql utilities and SQL Server Management Studio Code editor.

    SQL Server utilities interpret GO as a signal that they should send the current batch of Transact-SQL statements to an instance of SQL Server. The current batch of statements is composed of all statements entered since the last GO, or since the start of the ad hoc session or script if this is the first GO.

    A Transact-SQL statement cannot occupy the same line as a GO command. However, the line can contain comments.

    Users must follow the rules for batches. For example, any execution of a stored procedure after the first statement in a batch must include the EXECUTE keyword. The scope of local (user-defined) variables is limited to a batch, and cannot be referenced after a GO command.

    I note that neither the given syntax example nor the example code includes the iteration count parameter. Is this a stealth feature?

  • Lynn Pettis (9/11/2008)


    We never eliminate abiguity, just minimize it. As for the QotD, yes, they are a learning tool, but really will it matter tomorrow if you got the answer today right or wrong? What really matters is that you learned something from the question, and sometimes from the ensuing discussion.

    Yep I agree about assumptions, I do make them when I have to, but have an "accept no responsibility" disclaimer attached cos I was fed up being blamed for having to make them from other peoples shortcomings and then getting the sharp end when people changed their minds as of course it was my fault for assuming things that others wouldn't tell me; but anyway that's another topic for another time and another place and I only mentioned it cos I wanted to explain where my distaste of assumptions comes from.

    And I agree totally about learning something new. It's the reason i'm a member of sites like this as I'm still trying to work my way up. 🙂

    My issue was that I really wanted the ambiguity acknowledged. As you say the points don't matter at all. I'm never going to be right all the time (or even most of it :D), it's just I felt the ambiguity and the possibility that the answer was not completely clear cut was being dismissed.

    Sorry if I've caused any offense.

  • No offense taken. We both just have different perceptions from reading the question at hand. When the question started with In SQL Server 2005, I just automatically eliminated the use of all SQL Server 2000 tools, even though Query Analyzer will connect and work with SQL Server 2005 databases even though Enterprise Manager won't. Others, did not make that same assumption. Same is true of questions that specify SQL Server 2008. Even though I currently don't have the tools for SQL Server 2008, I will try to answer those questions based on what I know of its tools, not what happens with SQL Server 2005 tools connected to an instance of SQL Server 2008.

    Just seems to be the way it should be done.

    😎

  • This may be interesting to read

    http://sqlblogcasts.com/blogs/madhivanan/archive/2008/09/05/fun-with-go.aspx


    Madhivanan

    Failing to plan is Planning to fail

  • Thanks for this..............

  • good discussion :-P:w00t:

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

Viewing 7 posts - 31 through 36 (of 36 total)

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