Fun with GO

In SQL Server, GO is the default Batch Separator. Here is a Fun when you use GO as Stored Procedure name

Create the following stored Procedure with the name GO

CREATE PROCEDURE GO
(
    @I INT
)
AS
    SELECT @I AS number

The procedure is created and let us try to execute with the following statement

GO 2

What we see is

Command(s) completed successfully

Because it becomes a syntax to execute a batch for two times

EXECUTE GO 2 

Result is 2

Now I let you to try running the following statements to understand what happens

Execution 1

[GO] 2

Execution 2

[GO] 2
GO 2

Execution 3

[GO] 2
GO
EXECUTE GO 2
GO

Execution 4

[GO] 2
GO 2
GO 2

Execution 5

[GO] 2
GO
GO

Execution 6

EXECUTE GO 2
EXECUTE GO 2
GO 2

Execution 7

[GO] 2
GO
GO 2
GO 2
EXECUTE GO 2
GO
GO 2
GO 2
GO 2 
Execution 8
GO;

Execution 9

GO;2

Execution 10

GO 2;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s