Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Begin Transaction question Expand / Collapse
Author
Message
Posted Wednesday, April 8, 2009 7:29 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 7, 2013 11:45 AM
Points: 169, Visits: 282
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
Post #693071
Posted Wednesday, April 8, 2009 7:36 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, October 28, 2014 9:42 AM
Points: 1,800, Visits: 1,555
Above transaction will result in Deadlocks. This current SPID will allways be in a running state until commited or killed.
Post #693082
Posted Wednesday, April 8, 2009 8:05 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 10:03 AM
Points: 40,385, Visits: 36,829
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 2008, MVP
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

Post #693129
Posted Wednesday, April 8, 2009 8:08 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 10:03 AM
Points: 40,385, Visits: 36,829
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 2008, MVP
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

Post #693137
Posted Wednesday, April 8, 2009 8:10 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, October 28, 2014 9:42 AM
Points: 1,800, Visits: 1,555
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)
Post #693139
Posted Wednesday, April 8, 2009 9:25 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, August 24, 2012 8:11 AM
Points: 1,097, Visits: 2,157
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.

Post #693253
Posted Wednesday, April 8, 2009 12:27 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 7, 2013 11:45 AM
Points: 169, Visits: 282
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
Post #693437
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse