views:

19

answers:

2

I am working on SQL Server 2005 and I have come accros the issue that I have run the multiple update query on the single table one by one. As it takes lots of time to execute one by one I came to know that by using "GO" I can run the query one by one. Like this

Update Table A ....

GO

Update Table A

GO

Update Table A

I am not sure that I can put seperate update statement like this and it will run the query one by one. As I doing it on production I need to be sure that it should work.

Can anyone give me an example where I can see that by using GO, query runs one by one and not parallel?

+3  A: 

From GO (Transact-SQL)

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.

astander
As I am using SQL Server management studio, does it means that it will execute these update statement seperately ?
Zerotoinfinite
@Andrew Barber, please be aware that GO is an SSMS command, not TSQL, as I stated. So I think the best would be to get GO out of your mind entirely if you can X-)
astander
+1  A: 

Your queries will not be run in parallel whether or not you use the GO command. astander posted an answer explaining what GO is. Read that, then come back here.

Regardless whether you use the GO command, your script will be run one-statement-after-another. They are not run in parallel.

You can prove this by writing a script such as this (pseudo code, but you get the idea)

INSERT INTO MyTable ([id], [data]) VALUES (3, 'I am here')
DELETE FROM MyTable WHERE [id]=3

You can put a GO between those statements or not, the result will be the same: the first command will -always- fully complete before the second one is run.

Andrew Barber