Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Simple example of a transaction
Message
 
À
28/03/2006 13:54:37
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 7.0
Divers
Thread ID:
01108501
Message ID:
01108514
Vues:
18
This message has been marked as the solution to the initial question of the thread.
>Hello,
>I am trying to find a simple example of a transaction. I have 2 delete statements that I want to put in the same SP, but I either want it all to work or none of it to work.
>
>I tried googling but it's hard to find a simple example.
>
>Thanks a lot,
>MAC


Here is some code I have in an SP:
BEGIN TRANSACTION

DELETE FROM ProgramHdr 
WHERE ControlId = @ControlId
			
IF @@ERROR <> 0
BEGIN
  SET @OriginalError = @@ERROR
  RAISERROR ('Delete Error: ProgramHdr table. Error: %o.', 16, 1, @@ERROR)
  ROLLBACK TRANSACTION
  RETURN @OriginalError
END

DELETE FROM ProgramDtl 
WHERE ControlId = @ControlId
			
IF @@ERROR <> 0
BEGIN
  SET @OriginalError = @@ERROR
  RAISERROR ('Delete Error: ProgramDtl table. Error: %o.', 16, 1, @@ERROR)
  ROLLBACK TRANSACTION
  RETURN @OriginalError
END

-- At this point all rows should be deleted and it is safe to commit the transaction
COMMIT TRANSACTION
Hope this helps
Semper ubi sub ubi.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform