joining 'sys.dm_exec_query_stats' with other system tables.

  • Hi Experts,

    How can we relate the DMV 'sys.dm_exec_query_stats' to other sys tables like sys.objects or sys.databases so that I can atleast find the object id or the database id of the running queries, else I will have to search each and every database on the instance

    I am using this DMV to check the most expensive query.

    Regards,

    Ashif Shaikh:-)

  • cross apply that DMV to sys.dm_exec_sql_text, that DMV has the objectID and database (for procedures), you can join that to sys.objects/sys.procedures.

    Ad-hoc queries have neither an object ID or database ID associated with them.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks Got it,

    However for some queries the object id and the database id both are showing as NULL???

  • GilaMonster (6/26/2014)


    Ad-hoc queries have neither an object ID or database ID associated with them.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks a LOT

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply