Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

use go inside a transaction Expand / Collapse
Author
Message
Posted Thursday, March 3, 2011 4:26 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, October 22, 2013 11:43 AM
Points: 56, Visits: 249
This is just for my curiosity. Why I can use GO after the use statement?

Got syntax error if you execute the following.



BEGIN TRY
BEGIN TRAN T1
Use AdventureWorks
GO
COMMIT TRAN T1
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;
ROLLBACK TRAN T1
END CATCH;
Post #1073005
Posted Thursday, March 3, 2011 5:17 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 1:14 PM
Points: 40,615, Visits: 37,081
Nothing to do with the transaction. You can't use GO within the TRY.

GO is not a T-SQL command. It's a batch terminator. It marks where to break the code sent to SQL. With a GO there, you're telling SSMS to send the following as a batch to SQL

BEGIN TRY
BEGIN TRAN T1
Use AdventureWorks

I'm pretty sure you can agree that the block of code above is not valid.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1073018
Posted Friday, March 4, 2011 1:28 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, October 22, 2013 11:43 AM
Points: 56, Visits: 249
Make sense and thank you again!
Post #1073129
Posted Friday, March 4, 2011 3:57 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Wednesday, December 26, 2012 11:03 PM
Points: 586, Visits: 2,195

Just for the information to Know;

Go : Signals the end of a batch of Transact-SQL statements to the SQL Server utilities.

From the below you may get the idea:

declare @i int
set @i=1
select @i
GO
select @i /*will fail since the batch has been complited*/


Thanks
Parthi
Post #1073176
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse