Is exiting a stored procedure before using a commit harmful?

I tried searching for this but I have not found anything. If I have something like:

CREATE PROCEDURE QQ
AS

BEGIN TRANSACTION

BEGIN TRY

    -- return early and skip commit here
    IF (Condition = true)
      RETURN 0

    COMMIT TRANSACTION

END TRY

BEGIN CATCH

    ROLLBACK

END CATCH

What will happen with the transaction?

Answers


It will stay open until you COMMIT, ROLLBACK, or the connection is closed and that spid is killed.

This will block other processes and cause all kinds of other issues.

As a rule always run a check like below in your CATCH block to make sure you close up cleanly.

IF @@TRANCOUNT > 0
ROLLBACK

or

WHILE @@Trancount > 0
BEGIN
   ROLLBACK
END

Need Your Help

R multiply matrices: but with a special function

r plyr apply

I have two square matrices A and B. Both have either 1 or 0 in each of their entries. An example shown below

Custom UITableViewCell doesn't appear in the table

ios uitableview

I have created a UITableViewCell and I am trying to display it in one of my table, but for some reason it doesn't come, the table is coming empty. And when I click on the one of cell in the table it

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.