Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cancelling Transaction
Message
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
Cancelling Transaction
Versions des environnements
SQL Server:
SQL Server 2014
Application:
Web
Divers
Thread ID:
01611676
Message ID:
01611676
Vues:
60
Hi,
This is a very newbie question of SQL Server Stored Procedure (I am using SQL Server 2008)

The following is a pseudo code of a SQL Server procedure
BEGIN TRY
     BEGIN TRANSACTION
         update MyTable1 set Field1 = @SomeValue where Field2 = @SomeValue2
         IF @@ROWCOUNT = 0
         BEGIN
               -- at this point I want to Cancel the Transaction and return.  How?
         END

         update MyTable2 Set ....

         insert into MyTable3 ....

        COMMIT
END TRY

BEGIN CATCH
      IF @@TRANCOUNT > 0
          ROLLBACK
END CATCH
I have a couple of questions:
1. In the code above, on the first update I want to cancel if no record is found to be updated. How?
2. Is there a command END TRANSACTION is TSQL?

TIA
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform