• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

how to find on which query is taking lot of time and also table getting locked

our application is developed in sql server and java.this application will be hit by concurrent users.

we have written somewhat big queries in this application. sometimes tables are getting locked.we want to know during executing which query  this table is getting locked .can we have any option in toad to see these or do we have any queries to see this infornation?
chaitu chaitu
chaitu chaitu
  • 2
2 Solutions
im not that familiar with Toad
but you can look at the queries in text and any of the that have (tablock) in them are locking tables

here is a great article from MSDN (not a competing site)
regarding locks
looks like this has been asked before in EE
(also not a competing site)  :)


I did not write this answer I provided a link to it being answered by someone else prviously :)
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
The below DMV sys.dm_exec_query_stats call will give you the 100 longest running queries as of the last server restart.

SELECT TOP 100 query_stats.query_hash AS "Query Hash", 
    SUM(query_stats.total_worker_time) / SUM(query_stats.execution_count) AS "Avg CPU Time",
    MIN(query_stats.statement_text) AS "Statement Text"
    (SELECT QS.*, 
    SUBSTRING(ST.text, (QS.statement_start_offset/2) + 1,
    ((CASE statement_end_offset 
        WHEN -1 THEN DATALENGTH(ST.text)
        ELSE QS.statement_end_offset END 
            - QS.statement_start_offset)/2) + 1) AS statement_text
     FROM sys.dm_exec_query_stats AS QS
     CROSS APPLY sys.dm_exec_sql_text(QS.sql_handle) as ST) as query_stats
GROUP BY query_stats.query_hash

Open in new window

There are other DMV's that deal with sessions, index operations and usage, file usage, and partitions.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now