Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cancelling Transaction
Message
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
Cancelling Transaction
Environment versions
SQL Server:
SQL Server 2014
Application:
Web
Miscellaneous
Thread ID:
01611676
Message ID:
01611676
Views:
61
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
Next
Reply
Map
View

Click here to load this message in the networking platform