How to use Transation in Stored procedure ?

Ranjeet_8
Posted by Ranjeet_8 under Sql Server category on | Points: 40 | Views : 964
In this transaction UREG, both Insert queries executed. After the successfully execution of queries, transaction UREG is committed n then permanently save database changes. if (Table_loginInfo) insert query is not successful executed then CATCH block is executed here and ROLLBACK Command executed and remove all inserted row from each table.

begin try
begin tran UREG
declare @Uid int
insert into Table_UserInfo(name, email)
values('xyz','xyz@gmail.com')
select @Uid=max(userid) from Table_UserInfo
insert into Table_loginInfo( userid, username, password)
values(@userid,'singh','singh')
commit tran UREG
end try
begin catch
rollback tran UREG
end catch

Comments or Responses

Login to post response