use[OTAHARA]
Begin Transaction Trans1
--Código SQL
insert into Cities (Name) Values ('Teste 1')
UPDATE Customers Set IDCity = 20 Where ID = 1
If (@@ERROR <> 0)
begin
rollback
raiserror('Erro fidapu', 16, 1)
end
Else
begin
commit
end;
-- Selects
Select * from Cities
Select * From Customers Where ID = 1
=============================================== ==============
use[OTAHARA]
declare @idCity int = 0;
Begin Transaction Trans1
--Código SQL
insert into Cities (Name) Values ('Teste 2')
Select @idCity = @@IDENTITY;
Update Customers Set IDCity = @idCity where ID = 1
If (@@ERROR <> 0)
begin
rollback
raiserror('Erro fidapu', 16, 1)
end
Else
begin
commit
end;
-- Selects
Select * from Cities
Select * From Customers Where ID = 1
DELETE FROM Cities WHERE ID = 18;
=============================================== ==============