Detailed SQL Server Query table index

Source: Internet
Author: User
Tags sql server query

SELECT Index name =a.name

, table name =c.name

, indexed field name =d.name

, indexed field location =d.colid

?
12345678 FROMsysindexes  a JOINsysindexkeys  b  ONa.id=b.id  ANDa.indid=b.indid JOINsysobjects  c  ONb.id=c.id JOINsyscolumns  d  ONb.id=d.id  ANDb.colid=d.colid WHEREa.indid  NOT IN(0,255) -- and  c.xtype=‘U‘  and  c.status>0 --查所有用户表 ANDc.name=‘message‘ --查指定表 ORDER BYc.name,a.name,d.name

You need to create an index such as:

Determine if there is a duplicate record based on a column, and if it is a non-primary key, create an index

Create an index based on columns that are frequently queried

No need to create an index

The field content is mostly the same, for example: male, female

Do not create indexes on all columns, which increases the maintenance overhead time when new records are created.

Oracle Query User table index

?
1 selectindex_name,index_type,table_name from user_indexes wheretable_name=‘表名‘

SQL Server queries the index on a table

?
12345678910111213141516171819202122232425262728293031 SELECTTableId=O.[object_id],TableName=O.Name,IndexId=ISNULL(KC.[object_id],IDX.index_id),IndexName=IDX.Name,IndexType=ISNULL(KC.type_desc,‘Index‘),Index_Column_id=IDXC.index_column_id,ColumnID=C.Column_id,ColumnName=C.Name,Sort=CASE INDEXKEY_PROPERTY(IDXC.[object_id],IDXC.index_id,IDXC.index_column_id,‘IsDescending‘)WHEN 1 THEN ‘DESC‘ WHEN 0 THEN ‘ASC‘ ELSE ‘‘ END,PrimaryKey=CASE WHEN IDX.is_primary_key=1 THEN N‘√‘ELSE N‘‘ END,[UQIQUE]=CASE WHEN IDX.is_unique=1 THEN N‘√‘ELSE N‘‘ END,Ignore_dup_key=CASE WHEN IDX.ignore_dup_key=1 THEN N‘√‘ELSE N‘‘ END,Disabled=CASE WHEN IDX.is_disabled=1 THEN N‘√‘ELSE N‘‘ END,Fill_factor=IDX.fill_factor,Padded=CASE WHEN IDX.is_padded=1 THEN N‘√‘ELSE N‘‘ ENDFROM sys.indexes IDX INNER JOIN sys.index_columns IDXCON IDX.[object_id]=IDXC.[object_id]AND IDX.index_id=IDXC.index_idLEFT JOIN sys.key_constraints KCON IDX.[object_id]=KC.[parent_object_id]AND IDX.index_id=KC.unique_index_idINNER JOIN sys.objects OON O.[object_id]=IDX.[object_id]INNER JOIN sys.columns CON O.[object_id]=C.[object_id]AND O.type=‘U‘AND O.is_ms_shipped=0AND IDXC.Column_id=C.Column_id where O.name=‘cz201‘ --cz201是你要查询的表

The above content is all described in this article, I hope you like.

Detailed SQL Server Query table index

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.