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
 simple transaction

Author  Topic 

turj
Starting Member

6 Posts

Posted - 2007-11-21 : 03:37:16
hi,
I need some example for a simple transaction, (I looked in msdn and I didn't understood this.)
lets say I have 2 update queries. I want to run this queries in a transaction, and make it rollback if one of the updates failed.
I'm a developer and using php to exec all the queries, so I need a simple answer from the transaction, one row with one column the can be 'success' or 'failed.' thats it.

thanks.

cas_o
Posting Yak Master

154 Posts

Posted - 2007-11-21 : 04:19:16
Something like this should work.

begin tran t1

update table set column = value where column = criteria

if @@error <> 0
begin
rollback tran t1
select 'failed'
return
end

update table2 set column = value where column = criteria

if @@error <> 0
begin
rollback tran t1
select 'failed'
return
end
else
begin
commit tran t1
select 'success'
return
end


;-]... Quack Waddle
Go to Top of Page
   

- Advertisement -