Monday, 12 October 2015

To check how frequently the Database table is accessed in SQL Database Server

Hi All,
Being a Database expert or Monitoring the database or working on Data warehouse Project frequently we come across the scenario where query gets delayed, performance hampered etc.


So we can have some logical checks on the database by using the below query.


SELECT
  t.name AS 'Table',
  SUM(i.user_seeks + i.user_scans + i.user_lookups)
    AS 'Total accesses',
  SUM(i.user_seeks) AS 'Seeks',
  SUM(i.user_scans) AS 'Scans',
  SUM(i.user_lookups) AS 'Lookups'
FROM
  sys.dm_db_index_usage_stats i RIGHT OUTER JOIN
    sys.tables t ON (t.object_id = i.object_id)
GROUP BY
  i.object_id,
  t.name
ORDER BY [Total accesses] DESC




This will give you the below result





It will help you to build your indexes, monitor the much hitting tables and responsible for proper Database management.


Thanks & Regards
Mayur