Solved

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

Posted on 2012-03-30
3
1,711 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Suggested Solutions

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 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