Sample Stored procedure with Transaction and try Ctahc block

Create procedure [dbo].[sp_insertsample]
(@Secondname varchar(50)=null,@Address varchar(50)=null,@Age int=null,
@name varchar(50)=null,@unitPrice varchar(50)=null,@soldprice int=null)

as
Begin

    Begin Try
       Begin transaction t1

Declare @Error varchar(max)=null
insert into tbl_test2(Name,Address,Age)values(@Secondname,@Address,@Age)
WAITFOR DELAY '00:00:10'
insert into tbl_test3(Name,[Unit Price],[Sold Price])values(@name,@unitPrice,@soldprice)
commit transaction t1
   End Try
    Begin Catch
         
                rollback transaction t1
                     select
                     ERROR_NUMBER() as ErrorNumber,
                     ERROR_MESSAGE() as ErrorMessage

          
    End Catch


End


No comments: