What is the difference between “;” and “GO” in T-SQL?

后端 未结 7 858
抹茶落季
抹茶落季 2020-12-28 12:40

I use ADO.NET as well as the sqlcmd utility to send SQL scripts to SQL Server 2008. What is the difference between using ; and GO to separate chunk

相关标签:
7条回答
  • 2020-12-28 13:43

    "GO" is similar to ; in many cases, but does in fact signify the end of a batch.

    Each batch is committed when the "GO" statement is called, so if you have:

    SELECT * FROM table-that-does-not-exist;
    SELECT * FROM good-table;
    

    in your batch, then the good-table select will never get called because the first select will cause an error.

    If you instead had:

    SELECT * FROM table-that-does-not-exist
    GO
    SELECT * FROM good-table
    GO
    

    The first select statement still causes an error, but since the second statement is in its own batch, it will still execute.

    GO has nothing to do with committing a transaction.

    0 讨论(0)
提交回复
热议问题