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?
LVL 20
chaitu chaituAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.