Solved

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

Posted on 2012-03-30
3
1,455 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
Comment Utility
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
Comment Utility
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:
ScottPletcher earned 180 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sql Audit table 3 45
2008 to 2016 SQL migration.. 5 27
XML to SQL Table using c# 5 42
Sql Stored Procedure 26 26
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now