DMVs
From SQLServerPedia
What Are Dynamic Management Views (DMVs)?SQL Server 2005 introduced Dynamic Management Views (DMV's) and Dynamic Management Functions (DMF's) to expose much internal data that was very difficult or impossible to retrieve in SQL Server 2000. DMV's and DMF's are collectively referred to as dynamic management objects; these provide valuable insight into inner workings of software and can be used for examining the state of SQL Server instance, troubleshooting and performance tuning. In addition to providing a handy way of examining indexes, memory and I/O, transactions, locking and waits; dynamic objects also offer detailed information regarding various components of SQL Server. SQLServerPedia Editor Tim Ford's Favorite DMV Queriessys.dm_db_index_physical_statsProvides information about index fragmentation. Sample queries:
sys.dm_db_missing_index_detailsSQL Server constantly tracks what queries would have benefited from additional indexes. You can query this DMV to find out what indexes you might need to add. Before adding them blindly, though, carefully consider the performance impact. Sample queries:
sys.dm_exec_sql_textThis takes a SQL handle or plan handle, and returns the underlying database, object, and text of the query. This dynamic management object is most useful when combined with other DMVs. Sample queries:
sys.dm_exec_query_planLike sys.dm_exec_sql_text, this Dynamic Management Object takes a plan handle, but this one returns the XML query plan. Useful for performance tuning queries that reside in the plan cache. Sample queries:
sys.dm_exec_connectionsWhen sys.dm_exec_connections, sys.dm_exec_requests, and sys.dm_exec_sessions are used together, the DBA can find out what sessions are open and who's holding transactions open.
sys.dm_os_performance_countersJust like using Perfmon to access the SQL Server Performance Monitor counters, but it's available through T-SQL too. Only the SQL Server counters are available, though, not the Windows counters. sys.dm_db_file_space_usageThe name of this DMV is a little misleading - it only gives file space usage for TempDB, not for all user databases. Sample queries: sys.dm_tran_locksThis view returns one row per active lock. SQL Server 2000 users can get locking information with the stored procedure sp_lock. Sample queries:
sys.dm_os_waiting_tasksSample queries: sys.dm_exec_cached_plansThis DMV returns a list of all cached query plans. Sample queries: sys.dm_os_memory_objectsSample queries: More About Dynamic Management Views
|