In SQL Server, you need to check error for each SQL statement. For example if I have 3 updates in one transaction, I need some code like:
declare @HasError int
begin tran
Update tab1 set ....
Set @HasError = @@error;
Update tab2 set ...
Set @HasError = @@error;
Update tab3 set ...
Set @HasError = @@error;
If @HasError<>0
rollback tran;
else
commit tran;
Any other solution for this case with more simple code? for instance, something like c# style:
begin tran
try
{
Update tab1 set ....
Update tab2 set ...
Update tab3 set ...
commit tran;
}catch(error){
rollback tran;
}