Usage of SQL Server indexes

Source: Internet
Author: User

-In the Optimization query SQL statement, view the Index usage SQL statement:

Select Db_name (database_id) as N ' database name ',

object_name (a.object_id) as N ' table name ',

B.name N ' index name ',

User_seeks N ' user index lookup times ',

User_scans N ' user index Scan count ',

Last_user_seek N ' Last Find time ',

Last_user_scan N ' Last scan time ',

Rows as N ' table number of lines '

From Sys.dm_db_index_usage_stats a Join
Sys.indexes b
On a.index_id = b.index_id
and a.object_id = b.object_id
Join sysindexes C

On c.id = b.object_id

where database_id=db_id (' database name ')--Specify Database

and object_name (a.object_id) Not like ' sys% '

and object_name (a.object_id) Like ' table name '--Specify Index Table

and b.name like ' index name '--Specify the index name to use sp_help ' your table name ' to see the structure of the table and all the index information

Order by User_seeks,user_scans,object_name (a.object_id)

-In the Optimization query SQL statement, view the Index usage SQL statement:

Select Db_name (database_id) as N ' database name ',

object_name (a.object_id) as N ' table name ',

B.name N ' index name ',

User_seeks N ' user index lookup times ',

User_scans N ' user index Scan count ',

Last_user_seek N ' Last Find time ',

Last_user_scan N ' Last scan time ',

Rows as N ' table number of lines '

From Sys.dm_db_index_usage_stats a Join
Sys.indexes b
On a.index_id = b.index_id
and a.object_id = b.object_id
Join sysindexes C

On c.id = b.object_id

where database_id=db_id (' database name ')--Specify Database

and object_name (a.object_id) Not like ' sys% '

and object_name (a.object_id) Like ' table name '--Specify Index Table

and b.name like ' index name '--Specify the index name to use sp_help ' your table name ' to see the structure of the table and all the index information

Order by User_seeks,user_scans,object_name (a.object_id)

"/>

Usage of SQL Server indexes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.