Re: Simple locking question.....

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Louis Davidson (dr_dontspamme_sql_at_hotmail.com)
Date: 02/22/05


Date: Tue, 22 Feb 2005 12:23:25 -0600

Yes, any time you are modifying any resource, and viewing any resource
(unless you are in READ UNCOMMITTED isolation) you will have locks being
held for some duration (depending on which isolation level the length of
locks on viewing is variable.)

Usually, other processes simply wait until any other processes release the
locks that they were using before starting their own locks. So say process
1 locks resource X, if process 2 needs resource X, it will wait until
process 1 is finished.

Deadlocks come when two processes are blocking each other. So if in the
previous example, process 2 already had resource Y locked, and process 1 has
resource X locked, a deadlock would occur if process 2 needed X and process
1 needed Y. They are waiting on each other, so the would never complete
unless the other completed. Hence, one process has to be terminated (this
is called the victim)

Usually deadlocks are no problem whatsoever, you just redo your action you
wanted to do with the victim. As long as they are rare, I wouldn't worry
too much about it.

-- 
----------------------------------------------------------------------------
Louis Davidson - drsql@hotmail.com
SQL Server MVP
Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design - 
http://www.apress.com/book/bookDisplay.html?bID=266
Blog - http://spaces.msn.com/members/drsql/
Note: Please reply to the newsgroups only unless you are interested in 
consulting services.  All other replies may be ignored :)
"len" <len@discussions.microsoft.com> wrote in message 
news:10EC7E29-B955-4766-8B77-1041C2A49DEB@microsoft.com...
> Here's a simlple enough question:
>
> If somebody is deleting from a table in SQL (with a simple DELETE FROM...
> TSQL query), will there be a lock on this table such that another process
> can't
>  - UPDATE that table
>  - DELETE from that table
>  - SELECT from that table (not sure about this one)    ?
>
> I just got a rare "Transaction (Process ID 57) was deadlocked... chosen as
> deadlock victim" error msg from a process of mine and I just want to
> establish what the pther process may have been doing at the time.
>
> what I think happened was process X was deleting from the table and 
> process
> 57 tried an update.
>
> Q: Is is ok to run SELECT statements, if another process is deleting or
> inserting from a table?
>
> 


Relevant Pages

  • Re: Few questions on embedded stuff
    ... But a complex system with lots of resource locks can get into ... > locks, extensive design reviews and most of all strict discipline. ... and one of them is the use of a WDT. ...
    (comp.arch.embedded)
  • Re: Shared-memory between threads and synchronization
    ... In my project i am having different data structures ... shared memory is used for communication between processes. ... If process 1 locks resource a then resource b ...
    (comp.os.linux.development.system)
  • Re: File locking using threads
    ... lockf - provide semaphores and record locking on files ... (enforcement-mode record locks). ... resource becomes unlocked. ... will have an enforcement policy enabled. ...
    (comp.lang.perl.misc)
  • Re: Shareware licensing
    ... >> Locks only stop honest people anyway. ... What the cracker ... >> Veign's Resource Center ...
    (microsoft.public.vb.general.discussion)
  • Re: Locks and SQLAgent - Generic refresher, Alert Engine
    ... Our SQL Server 2000 is on a VM Virtual server, ... We are also on SQL 2000 sp4, and ran into deadlocks while processing a ... observe locks acquired and released long enough, ... RID, IDX,PAG,tab) and corresponging resource like ...
    (microsoft.public.sqlserver.server)