--启用事务
begin
begin tran myTran
declare @id int
insert Date2(date2) values(GETDATE())
--获得插入数据的主键值
select @id= @@IDENTITY
select * from Date2 where id=@id-1
--调用其他的存储过程
exec mySelProc @id
--事务回滚
if(@@ERROR<>0)
rollback tran myTran
else
commit tran myTran
end
(备注:存储过程定义)
create proc [dbo].[mySelProc]
@ID1 INT
as
begin
BEGIN TRANSACTION
select id,date2 from Date2 where id=@ID1
if @@ERROR <>0
begin
rollback transaction
end
else
begin
commit transaction
end
end
GO