Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Begin Transaction question


Begin Transaction question

Author
Message
Subhash-63067
Subhash-63067
SSC Veteran
SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)

Group: General Forum Members
Points: 203 Visits: 295
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
Mayank Khatri
Mayank Khatri
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1869 Visits: 1700
Above transaction will result in Deadlocks. This current SPID will allways be in a running state until commited or killed.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)

Group: General Forum Members
Points: 55547 Visits: 44699
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


GilaMonster
GilaMonster
SSC Guru
SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)

Group: General Forum Members
Points: 55547 Visits: 44699
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


Mayank Khatri
Mayank Khatri
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1869 Visits: 1700
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)
maechismo_8514
maechismo_8514
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1248 Visits: 2228
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.
Subhash-63067
Subhash-63067
SSC Veteran
SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)

Group: General Forum Members
Points: 203 Visits: 295
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search