Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Transaction syntax
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
Transaction syntax
Divers
Thread ID:
00686750
Message ID:
00686750
Vues:
82
Im trying to find the best way to run transactions with T-SQL. This is how im doing it..
begin transaction

declare @err1 int, @err2 int
/* Add a record to students */
insert into students (studentID, lastname, firstname, middleini, ...)  values (@studentid, @lastname, @firstname, ...)
set err1 = @@error

/* Log the move */
if @logmove = 1
  insert into movelog (studentID, hallfrom, ...) values (@studentID, 'NEW', ...)
set @err2 = @@error

if @err1 = 0 and @err2 = 0
begin
  commit transaction
    set @return = 'Move successfull'
end
else
  begin
     rollback transaction
     set @return = 'Unable to move student out. The transaction did not complete.'
 end
Im just wondering if there is an eaiser way to accomplish this?

TIA
Eric Stephani
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform