Re: Select statement Causing Table Locks

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



Ok, it is technically a blocking chain, but this query does not continue. It
is blocking updates to the two tables from other users. It holds exclusive
locks on the tables themselves.


objectowner objectname indid indexname locktype resource lockreq status
dbo Task 1 TASKRECID Page 1:1029887 Exclusive Granted
dbo Incident 0 Table Schema modification Granted
dbo Incident 0 Table Schema modification Granted
dbo Incident 0 Table Exclusive Granted
dbo Task 1 TASKRECID Page 1:1230305 Exclusive Granted
dbo Task 1 TASKRECID Key (ca0180e2e8e9) Schema modification Granted
dbo Task 0 Table Exclusive Granted
dbo Task 0 Table Exclusive Granted
dbo Task 0 Table Exclusive Granted
dbo Task 1 TASKRECID Page 1:1029887 Exclusive Granted
dbo Incident 0 Table Schema modification Granted
dbo Incident 0 Table Schema modification Granted
dbo Incident 0 Table Exclusive Granted
dbo Task 1 TASKRECID Page 1:1230305 Exclusive Granted
dbo Task 1 TASKRECID Key (ca0180e2e8e9) Schema modification Granted
dbo Task 0 Table Exclusive Granted
dbo Task 0 Table Exclusive Granted
dbo Task 0 Table Exclusive Granted
dbo Task 1 TASKRECID Page 1:1029887 Exclusive Granted
dbo Incident 0 Table Schema modification Granted
dbo Incident 0 Table Schema modification Granted
dbo Incident 0 Table Exclusive Granted




"Erland Sommarskog" wrote:

John Couch (JohnCouch@xxxxxxxxxxxxxxxxxxxxxxxxx) writes:
I have a database on a sql server 2005 instance running under
compatability mode. A user is executng the below statement, and it is
causing deadlocks by holding table locks on all the tables in the from
clause. I tried using nolock, but it doesn't prevent it. Any thoughts?

Deadlocks? Who is the deadlock victim? This query or someone else?

To be precise, a deadlock is when two or more processes all block each
other, so that no one can continue.

SQL Server will detect deadlock situations, and will terminate requests
until the deadlock has been resolved. This usually takes a couple of
seconds.

On the other hand, if this goes on forever, then it's just a blocking
situation. Which certainly can be nasty, but it is not a deadlock.


SELECT Incident.IncidentNumber,
Incident.Company,
Incident.Priority,
Incident.TypeOfIncident,
Incident.Subject,
Task.AssignmentQue,
Incident.CreatedDateTime,
Task.CreatedDateTime,
Incident.ResolvedDateandTime,
Incident.Category,
Task.AssignmentGroup
FROM {oj ITSM.dbo.Task Task with (ROWLOCK) LEFT OUTER JOIN
ITSM.dbo.Incident
Incident with (ROWLOCK)

Where you have ROWLOCK and not NOLOCK.

NOLOCK may not be the best solution, as it could result in incomplete
data, or errors due to data movement.

Have you considered to put the database in READ COMMITTED SNAPSHOT?
(This should work even if the database in compat mode 80.)



--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx


.



Relevant Pages

  • Re: JDBC Driver for Windows 2003 Server
    ... | Subject: Re: JDBC Driver for Windows 2003 Server ... You can troubleshoot the blocking problem using the SQL Server ... You can run "sp_lock" in Query Analyzer to see the specific locks that are ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: Help with blocking on querying two joined tables
    ... > to SQL Server 2000 that query a view made up of two joined tables. ... > tables directly I still get the same blocking. ... If these tables are queried frequenly they should stay in cache. ...
    (comp.databases.ms-sqlserver)
  • Deadlocks and Parallel Query Processing
    ... SQL Server 2000 SP3A ... Last week one of our processes starting issuing or suffering deadlock ... detected errors every 15 minutes or so. ... best I can tell from trying to query the actual data each update hits ...
    (comp.databases.ms-sqlserver)
  • Re: How to Use Activity Monitor
    ... teach me this area of SQL Server administration? ... First of all, in case you don't know the timeout is in the client API, ... The query is taking longer the time to execute than the client will ... In case of blocking, well that is likely to resolve sooner or later ...
    (microsoft.public.sqlserver.tools)
  • Re: SQL Timeout Errors - Can Anyone Help?
    ... The timeout period elapsed prior to completion of the ... SQL Server does not time out. ... and you get further blocking and timeout. ... There are two possible reasons why a query takes more than 30 seconds ...
    (comp.databases.ms-sqlserver)