0

Is there a way, or a stored procedure or query that I can run, to get a list of all the queries/transactions that previously ran on the database and are locking tables.

I am looking into doing an analysis to see which transactions are locking what tables.

TT.
  • 15,774
  • 6
  • 47
  • 88
devista
  • 55
  • 3
  • 10
  • All queries are locking tables to various degrees at all times, but it's not a problem unless it is impacting performance or causing deadlocks. Do you have a performance or deadlock issue that you're trying to solve? – Nick.Mc May 27 '16 at 02:17
  • If you need that kind of data, you'll have to gather it yourself (or use a 3rd party tool) – James Z May 27 '16 at 03:52
  • @Nick.McDermaid Yes that is exactly what I am looking for. Any idea how I can do that. – devista May 27 '16 at 13:06
  • Your question remains far too general to pose a specific answer. Why don't you start here : http://stackoverflow.com/questions/694581/how-to-check-which-locks-are-held-on-a-table – Nick.Mc May 28 '16 at 06:52

1 Answers1

0

It's a more tricky question that it seems.

Historical data regarding locking, as long as we aren't talking about something like "query store" or some other technology that can be thought of as "external", is accumulated by DMV sys.dm_db_index_operational_stats.

This DMV is relatively stable. But its counterpart sys.dm_exec_procedure_stats has a propensity to change as soon as particular plan, which could accumulate some "interesting" data, is recompiled.

This transient property of accumulated data tends to be more pronounced as the rate of change of statistics gets higher. So, you can see that sometimes (or even most of the times) you might not get an exact link between a lock and its cause using DMV from **stats family, but knowing how the omission occurs, you have some information to make good judgment.

Add sys.sql_dependencies linking lock impacted objects and procedures, and it is a starting point.

Please note additional resources for ***stats DMV family:

TT.
  • 15,774
  • 6
  • 47
  • 88