• Thanks for this. Very timely. I'm just barely getting started in R and this was extremely useful.

    A couple of notes though. The query you start with, it has an ORDER BY clause on a column that's not defined. I changed my query like this:

    SELECT OBJECT_NAME(ops.object_id) AS [Object Name],

    SUM(ops.range_scan_count) AS [Range Scans],

    SUM(ops.singleton_lookup_count) AS [Singleton Lookups],

    SUM(ops.row_lock_count) AS [Row Locks],

    SUM(ops.row_lock_wait_in_ms) AS [Row Lock Waits (ms)],

    SUM(ops.page_lock_count) AS [Page Locks],

    SUM(ops.page_lock_wait_in_ms) AS [Page Lock Waits (ms)],

    SUM(ops.page_io_latch_wait_in_ms) AS [Page IO Latch Wait (ms)],

    SUM(ops.row_lock_count) AS [RowCount]

    FROM sys.dm_db_index_operational_stats(NULL, NULL, NULL, NULL) AS ops

    INNER JOIN sys.indexes AS idx

    ON idx.object_id = ops.object_id

    AND idx.index_id = ops.index_id

    INNER JOIN sys.sysindexes AS sysidx

    ON idx.object_id = sysidx.id

    WHERE ops.object_id > 100

    GROUP BY ops.object_id

    ORDER BY [RowCount] DESC;

    Is that what you were originally going for, or should I just ignore the ORDER BY clause?

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning