March 3, 2011 at 4:26 pm
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;
March 3, 2011 at 5:17 pm
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, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 4, 2011 at 1:28 am
Make sense and thank you again!
March 4, 2011 at 3:57 am
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
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply