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 2005 Forums
 Transact-SQL (2005)
 Executing Multiple Updates statements

Author  Topic 

sureshg03
Starting Member

1 Post

Posted - 2010-11-23 : 09:28:25
Dear All,

i have a few update statements as given below

Update ocry set Country='AN' Where name='x'
Update ocry set Country='AS' Where name='y'
Update ocry set Country='AT' Where name='z'
Update ocry set Country='AF' Where name='a'

I m running the above queries in my sql server

I just want to know, what will happen, if there is error in
second line

will first line rollback or third, fourth line won't execute

Pls Help

Regards
Suresh G

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-11-23 : 09:33:44
first won't roll back unless you have an open transaction. 3rd and 4th probably won't execute but may
try

begin try
begin tran
Update ocry set Country='AN' Where name='x'
Update ocry set Country='AS' Where name='y'
Update ocry set Country='AT' Where name='z'
Update ocry set Country='AF' Where name='a'
commit tran
end try
begin catch
rollback tran
select 'failed'
end catch


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -