开发者

difference in executing a single line query with and without GO keyword

开发者 https://www.devze.com 2023-02-14 16:59 出处:网络
what\'s the dif开发者_开发问答ference in executing below query with and without GO keyword use hello

what's the dif开发者_开发问答ference in executing below query with and without GO keyword

use hello


use hello
GO

i am using use database query, it could be insert, select or any query.


GO isn't actually part of the query for SQL. Tools like SSMS use it to know in a block of statements to send them individidually. So think of GO as a seperator.

So..

SELECT ...

GO

SELECT ...

Will be sent to SQL as two seperate commands and not just one.


It depends on how it is executed. If you simply execute use hello in SSMS, it is equivalent to

use hello;
GO

I.e., when you execute a statement by itself, it is being executed as its own batch. However, if you execute the following SSMS:

use hello;
GO
Select 'hello'

, you are executing two batches which are separated by the GO keyword. From C#, outside of using the SQL Server SMO, you cannot execute a script with multiple batches using a Command object (e.g. SqlCommand). I.e., when you use a Command object from C#, it cannot contain the GO keyword.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消