Sunday, October 3, 2010

SQL Server GO Keyword

Often we face problem when executing multiple SQL statements i.e. if any one among the SQL statements fail then all transactions may fail.
To overcome this problem in SQL Server, we can use GO keyword which we will seperate execution of one statement from the other SQL statement.

Syntax:
GO [Count]
Where Count Is a positive integer. The batch preceding GO executes the specified number of times.
Example:
Create Employee(Id int,Name Varchar(50))

INSERT INTO Employee(Id ,Name)
VALUES (100,'Emp1')

INSERT INTO Employee(Id ,Name)
VALUES (100,'Emp2)

Execution above statements fails as there is syntax error.

Using the GO keyword.
INSERT INTO Employee(Id ,Name)
VALUES (100,'Emp1')
GO
INSERT INTO Employee(Id ,Name)
VALUES (100,'Emp2)
GO
Now the 1st statement will be executed successfully.
To know more about the GO keyword click link here.

Reference: http://blogwithdp.blogspot.com/

No comments:

Post a Comment