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
 Transact-SQL (2000)
 sql transaction

Author  Topic 

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2006-03-06 : 11:45:57
I have created three stored procedures.
Each one has a begin transaction and commit transaction and in the begin catch statement it has rollback transaction.

i.e.
create procedure sp1

as

begin try

begin transaction
insert into table1(field1) values('field1')
insert into table2(field2) values('field2')
end transaction
end try

begin catch
rollback transaction
end catch
--------------------------------
create procedure sp2

as

begin try

begin transaction
insert into table3(field3) values('field3')
insert into table4(field4) values('field4')

end transaction
end try

begin catch
rollback transaction
end catch
--------------------------------
create procedure sp3

as

begin try

begin transaction
insert into table2(field5) values('field5)'
insert into table2(field5) values('field5)'
end transaction
end try

begin catch
rollback transaction
end catch
---------------------------------

NOW I would like to create one stored procedure to call the above three procedures
i.e.
create procedure spMain

as

begin try

begin transaction
execute sp1
execute sp2
execute sp3
end transaction
end try

begin catch
rollback transaction
end catch

???????????????????????????????
is what I have done correct for spMain ?
It's just that in each individual SP there is rollback transaction. I have also placed it in the catch statement for spMain.
My concern is that what happens if there is an error in spMain say in exececute sp3 ?

Thanks
   

- Advertisement -