Begin Transaction question

  • there is a stored procedure with the following code

    Begin transaciton

    --update =56

    -----lots of select code in between no DML

    select =56

    ----- lots of select code in between no DML

    --commit transaction

    The update statement and commit was commented as part of some changes to the procedure but they forgot to comment the begin transaciton. this procedure is being called many times without any failures.

    Question: what will be the impact due to this proc which has only begin tran with only select statements and NO DML and NO commit tran


    subban

  • Above transaction will result in Deadlocks. This current SPID will allways be in a running state until commited or killed.

  • The transactions will never be committed, the locks those updates take will be held until the connection is closed. When the connection is closed, because there has been no commit statement issued, SQL will roll back all changes.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Mayank Khatri (4/8/2009)


    Above transaction will result in Deadlocks.

    Why do you say that? Locks and blocking it will definitely cause, but with only one update, it's unlikely to deadlock, unless there's more to it than we've been shown.

    This current SPID will allways be in a running state until commited or killed.

    Actually not. Once the last of the selects has finished, the state of the connection will be sleeping. Only connections that are currently running queries have a running state. A connection can be sleeping with open transactions.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Transaction cane be commited if u use commit tran on the same SPID or client that had started executing your T-SQL queries. (i.e. same window)

  • Subhash (4/8/2009)


    Question: what will be the impact due to this proc which has only begin tran with only select statements and NO DML and NO commit tran

    and also will bloat your Tlog file.

  • As the code didn't display properly updating it correct as below

    Begin transaciton

    --update tablename set column2=1 where column1=56

    -----lots of select code in between no DML

    select * from tablename where column1=56

    ----- lots of select code in between no DML

    --commit transaction

    There is no update and no commit, all it does is a begin tran and a select. (the reason i put the update and commit commented because it was there in the procedure before and commented later but the developer forgot to comment the begin tran.

    Having said the above, what will happen if there is a BEGIN TRAN and followed by a SELECT without commit.

    I have observed no Opentran due to this


    subban

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply