Solved

What happen if i forgot to give Commit transaction after begin trans?

Posted on 2012-03-30
3
1,596 Views
Last Modified: 2012-04-02
I update the table along with Begin trans in the sql Query window and forgot to give commit trans and close the Query window. Can you please tell what happens?

Begin trans
Update DBName..tablename set name ='xxx' where name='yyy'

1. The Specific database locked and no other user access the database/Table?
2. whatever updated rollback automatically
3, What happen if i open new sql query window and give commit transaction after 2 to 3 hours.
4. And how to find out if someone forgot to give commit transaction after Begin Trans.

Please clarify me. Thanks.
0
Comment
Question by:PKTG
3 Comments
 
LVL 11

Assisted Solution

by:rowansmith
rowansmith earned 140 total points
ID: 37785962
The default timeout is infinity.  You can change this by using SET LOCK_TIMEOUT

See: http://msdn.microsoft.com/en-us/library/ms189470.aspx

When your Client Disconnects, SQL Server will realize this has happened and will free the locks.

When you reconnect you are a new session, it is not possible commit a transaction in another session.  (There may be some "black-magic" way of finding an open transaction and forcing it to commit as an administrator, but I doubt very much it would be supported - you've got no way of knowing if the client finished its processing.

You can use SQL Enterprise Manager to view the current Locks.
0
 

Author Comment

by:PKTG
ID: 37787166
Thanks for the info. I understand below answer from you reply. Please correct me if i am wrong.

1. The Specific database locked and no other user access the database/Table?
--Create lock and it will affect user to access the db
2. whatever updated rollback automatically
--yes
3, What happen if i open new sql query window and give commit transaction after 2 to 3 hours.
-not able to commit
4. And how to find out if someone forgot to give commit transaction after Begin Trans.
--no way to find
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 180 total points
ID: 37787403
1. For an UPDATE on every row like that one,  the table would be locked and no other user could access the table, *expect* they can SELECT from the table using (NOLOCK) or the equivalent isolation level setting.
[No UPDATE ever locks out the whole db.]

2. No.  Rollback is not automatic by default.  By default the system will wait until you do either a commit or rollback.

3.  A new query window would be a different session, with its own separate transaction, and so would not affect the original trans one way or the other.

4. USE [database_name] DBCC OPENTRAN will show you the single oldest transaction.  You can also look at system views to find all locks being held and/or blocking occuring.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question