An Introduction to Dynamic Management Views and Functions in SQL Server 2005
2009-04-21 13:44
621 查看
An Introduction to Dynamic Management Views and Functions in SQL Server 2005
By : Brad McGehee Feb 08, 2007 |
While DMVs and DMFs provide a wealth of information, the information they provide is often esoteric or difficult to understand. Because of this, there is a fairly steep learning curve when using them. In addition, you must use Transact-SQL to SELECT the results you want, so you must have a basic understanding of how to write SELECT statements in order to take full advantage of them.
The purpose of this article is to introduce you to them at a high level; in later articles, I will drill down into how specific DMVs and DMFs can be used to help you performance tune your servers and databases.
The Basics
There are two different kinds of DMVs and DMFs:Server-scoped: These look at the state of an entire SQL Server instance.
Database-scoped: These look at the state of a specific database.
All DMVs and DMFs exist in the master database and belong to the sys schema. They also follow the naming convention of dm_*, such as:
sys.dm_db_index_usage_stats
DMVs can be referred to in Transact-SQL using the DMVs two-part, three-part, or four-part name. DMFs have to be referred to using either their two-part or three-part names in code. Neither DMVs nor DMFs can be referred to with their one-part name. The two-part name example above is the most common way to refer to DMVs and DMFs.
To access a DMV or DMF, the user must have SELECT permission on the specific DMV or DMF they want to access and must have either VIEW SERVER STATE or VIEW DATABASE STATE permission, depending on if the DMV or DMF is server- or database-based. By default, members of the sysadmin group have these permissions.
To view the data provided by a DMV or DMF, you use the SELECT statement. Here's a simple example:
SELECT * FROM sys.dm_db_index_usage_stats
This produces results like the following:
![](http://writeblog.csdn.net/images/bm_dmvs_and_dmfs_intro.gif)
Figure: This output from the sys.dm_db_index_usage_stats DMV has been greatly abbreviated to fit the available space.
As you can see just from this one example, results from a DMV or DMF can be very detailed, but also very difficult to interpret without a little, or a lot of help. To be able to fully understand the capabilities of DMVs and DMFs, you will need to read up on each one and experiment with them to see if the information they provide is beneficial to you. In some cases, you may have to write some very complex Transact-SQL to produce the results you need. Books Online has some examples of Transact-SQL code you can use for various DMVs and DMFs.
Classes of DMVs and DMFs
Because there are so many DMVs and DMFs available, Microsoft has grouped them into categories. They include:Common Language Runtime Related Dynamic Management Views
I/O Related Dynamic Management Views and Functions
Database Mirroring Related Dynamic Management Views
Query Notifications Related Dynamic Management Views
Database Related Dynamic Management Views
Replication Related Dynamic Management Views
Execution Related Dynamic Management Views and Functions
Service Broker Related Dynamic Management Views
Full-Text Search Related Dynamic Management Views
SQL Server Operating System Related Dynamic Management Views
Index Related Dynamic Management Views and Functions
Transaction Related Dynamic Management Views and Functions
Each of the above categories has many different DMVs and DMFs. While we don't have time in this article to look at them all, let's take a quick look at those that fall in the Index Related Dynamic Management Views and Functions category, one of the most useful categories of DMVs and DMFs used in performance tuning. They include:
sys.dm_db_index_operational_stats
sys.dm_db_index_physical_stats
sys.dm_db_index_usage_stats
sys.dm_db_missing_index_columns
sys.dm_db_missing_index_details
sys.dm_db_missing_index_group_stats
sys.dm_db_missing_index_groups
While the name of the DMV or DMF is somewhat useful when figuring out what information they provide, you will find yourself looking these up in Books Online, or just experimenting by trail and error, to find out what information they can provide you.
Summary
DMVs and DMFs, along with data provided by Management Studio, System Monitor, and Profiler, provide DBAs with a wealth of information they can use to troubleshoot and correct SQL Server performance problems, in addition to many other SQL Server-related problems. If you have not yet done so, take some time and look up the more interesting DMVs and DMFs in Books Online and give them a try.相关文章推荐
- How to Implement an Automatic Sliding Window in a Partitioned Table on SQL Server 2005
- How to build an OLE DB application for SQL Server CE in Visual Studio 2005
- How to monitor blocking in SQL Server 2005 and in SQL Server 2000 [ZT-MS]
- Introduction to XQuery in SQL Server 2005
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
- Top 10 steps to optimize data access in SQL Server: Part II (Re-factor TSQL and apply best practices)
- How to Alter a Replicated Article in SQL Server 2005
- An introduction to JSON support in Spark SQL
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
- About UID and How to autostart an application on boot up in 3rd- Startup List Management API
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
- MySql 执行语句错误 Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
- Index Fragmentation Report in SQL Server 2005 and 2008
- Transact SQL User-Defined Functions in SQL Server 2005
- Introduction to Locking in SQL Server
- Introduction to SQL Server 2005 XML
- Problem to create "New Database Diagram" in Microsoft SQL Server Management Studio for SQL Server 2012
- Error message when you try to install a SQL Server 2005 service pack or a SQL Server 2005 hotfix package: "Error 29528. The setup has encountered an unexpected error while Setting Internal Properties"
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versio