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

后端 未结 7 856
抹茶落季
抹茶落季 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:22

    GO is not actually a T-SQL command. The GO command was introduced by Microsoft tools as a way to separate batch statements such as the end of a stored procedure. GO is supported by the Microsoft SQL stack tools but is not formally part of other tools.

    You cannot put a GO into a string of SQL and send it as part of a ADO.NET command object as SQL itself does not understand the term. Another way to demonstrate this is with the profiler: set up some statements that use GO in Query Analyzer/Management Studio and then run the profiler when you execute. You will see they are issued as separate commands to the server.

    The semi-colon is used to signify the end of a statement itself, not necessarily a whole batch.

    http://msdn.microsoft.com/en-us/library/ms188037.aspx

提交回复
热议问题