What a "GO" statement do in T-SQL ?
Sep 13, 2011
What a "GO" statement do in T-SQL ?
By definition it is a batch separator. It will run a batch and commit it. But along with that it also accepts one parameter which tells the SQL engine basically how many times to do the job.
For Example:
Note: "GO" is the keyword used by SSMS to separate query batches. It can be configured in this location:
Tools » Options » Query Execution » SQL Server » General. Change the value for "Batch Separator:" in the right pane.
To see the immediate effect of this change, you need to close all query windows in the current session and open new query window.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCKRmSgDaITrYSm8r4X1dHQZe28Qwg2j23e8VqHfMHyMKm2dTMJsOp4xjpv-nvPOfUNQALQhTmd5V_KlGAihD3BGWjLeSD8AdK33L6ws6DewPP3_-YJ1eQvEE4Rs6ckGmJeJ0vW7jqBvU/s400/GoNTimes2.png)
Next Example:
OUTPUT:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirqQuzz0yrPsotYLHZ9689d79RaUS6Noxl9Wcvslj7v94RjjErNvN7o1zJjfsv9AclMJoXc9wEU7smDFBYmpn_pq9-40oGqBj3pLhbVRpT9s9BedCsC2jWxnwHyJsOz4xTo22H4AP32wY/s400/GoNTimes1.png)
Hope this helps you and thanks to SQLLion.
By definition it is a batch separator. It will run a batch and commit it. But along with that it also accepts one parameter which tells the SQL engine basically how many times to do the job.
For Example:
SELECT * FROM sys.objects;It will show the output THREE times :)
GO 3
Note: "GO" is the keyword used by SSMS to separate query batches. It can be configured in this location:
Tools » Options » Query Execution » SQL Server » General. Change the value for "Batch Separator:" in the right pane.
To see the immediate effect of this change, you need to close all query windows in the current session and open new query window.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCKRmSgDaITrYSm8r4X1dHQZe28Qwg2j23e8VqHfMHyMKm2dTMJsOp4xjpv-nvPOfUNQALQhTmd5V_KlGAihD3BGWjLeSD8AdK33L6ws6DewPP3_-YJ1eQvEE4Rs6ckGmJeJ0vW7jqBvU/s400/GoNTimes2.png)
Next Example:
IF EXISTS (SELECT 1
FROM tempdb.sys.objects
WHERE name LIKE '%#ProductTable%')
DROP TABLE #ProductTable;
CREATE TABLE #ProductTable
(
ID INT IDENTITY (1, 1),
Name VARCHAR (50)
);
GO
INSERT INTO #ProductTable (Name) VALUES ('Office XP');
GO 3
SELECT * FROM #ProductTable;
OUTPUT:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirqQuzz0yrPsotYLHZ9689d79RaUS6Noxl9Wcvslj7v94RjjErNvN7o1zJjfsv9AclMJoXc9wEU7smDFBYmpn_pq9-40oGqBj3pLhbVRpT9s9BedCsC2jWxnwHyJsOz4xTo22H4AP32wY/s400/GoNTimes1.png)
Hope this helps you and thanks to SQLLion.
Share
Labels:
SQL SERVER,
SQL Server 2008,
T-SQL