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
 General SQL Server Forums
 New to SQL Server Programming
 begin end in stored procedure

Author  Topic 

CrazyT
Yak Posting Veteran

73 Posts

Posted - 2010-04-29 : 14:35:01
I have a query that pulls 25k reocrds into a temp table

i begin trans

it then updates one table, inserts into another, and then updates a 3rd.

end trans and commits

do i need to surround each one with a begin end if i want to wait for the first to finish, then the second, etc

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-29 : 14:41:48
No, that's not how it works. It doesn't go to the next command until the previous command completes.

You need to also check for errors to determine if a rollback is required. You should look into TRY/CATCH if you are using 2005 or 2008.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-30 : 01:48:24
if you want to capture errors in b/w wrap all of them inside TRY block as Tara suggests. Errors will be captured by TRY block and you can do apropriate actions inside CATCH block. For version before 2005 use IF @@ERROR > 0 check and do rollback and raise error messages.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -