Professional Documents
Culture Documents
Transactions
Transactions
Understanding Transactions:
============================================================================
-- CREATE a Procedure
create procedure sp_Trans_Test
@newpersonid nvarchar(5),
@newfirstname nvarchar(10),
@newcompanyname nvarchar(15),
@oldpersonid nvarchar(5)
as
declare @inserr int
declare @delerr int
declare @maxerr int
set @maxerr = 0
begin transaction
-- Add a person
insert into person (personid, firstname, company)
values(@newpersonid, @newfirstname, @newcompanyname)
-- Delete a person
delete from person
where personid = @oldpersonid
set @delerr = @@error -- Save error number returned from Delete statement
• Try to insert new person and try to delete a person who has child
records in the PersonDetails table.
exec sp_Trans_Test 'ag', 'Agarwal ',null, 'Vidvr'