begin transaction
declare @NewId int
begin transaction
INSERT INTO [CUSTOMER_TABLE] (Name) VALUES ('sam')
set @NewId = @@Identity
if @@ROWCOUNT = 0 begin -- if no rows were inserted
rollback transaction -- rollback
return -- stop doing stuff
end
insert into [Address_TABLE] (Cust_ID,Addr_Line1) VALUES (@NewId,'Test St')
if @@ROWCOUNT = 0 begin -- if no rows were inserted
rollback transaction -- rollback
return -- stop doing stuff
end
commit transaction -- save changes
|