Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 GO required for TRANS?

Author  Topic 

influent
Constraint Violating Yak Guru

367 Posts

Posted - 2006-09-22 : 19:56:53
If I have a transaction that starts and ends inside of a loop or cursor, do I need to say "GO" after each COMMIT TRANSACTION for the transaction to actually be committed?

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-09-22 : 20:20:44
No - in fact you may get errors if you try to do that. GO isn't actually a SQL Server T-SQL statement at all. It is a Query Analyzer and osql command that tells the client to send a batch to the server, it has no effect on a transaction, but there are certain things that you have to within a batch, so if you have a GO in the wrong place it will cause problems.

For example, this will give you an error because you cannot declare a variable in one batch and use it in another batch

DECLARE @test int
GO
SET @test = 1

With cursors, whether or not you can use a cursor across batches depends on whether you declare the cursor as local or global, if local then the cursor will be unavailable after you use GO. Also for this reason, you cannot put a GO anywhere in a stored procedure.
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-09-22 : 20:25:42
GO
Signals the end of a batch of Transact-SQL statements to the Microsoft® SQL Server™ utilities.


Read books online

Afrika
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-23 : 11:41:50
Refer sql server help file for more informations

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -