Method 1. Working with system tables
--Query indexes and index columns in a table use adventureworks2008goselect indexname = a.name, TableName = c. name, Indexcolumns = d. Name, A. Indidfrom sysindexes A join Sysindexkeys B on a. id = B. ID and a. indid = B.indid JOIN sysobjects C on B. Id = c. ID JOIN syscolumns d on b. ID = d. ID and b. colid = d. colidwhere A. Indid not in (0, 255) --and c.xtype= ' U ' and c.status>0--Check all user tables and C. name = ' DatabaseLog '--Check the specified table order by C. Name, A.name,
d.name
Method 2. Using System stored Procedures
Sp_helpindex: Reports information about indexes on a table or view.
/* Sp_helpindex [@objname =] ' name ' parameter: [@objname =] ' name ' is the name of the table or view in the current database. The data type of name is nvarchar (776) and has no default value. */use db_namegosp_helpindex ' Tablename '
Returns the code value 0 (success) or 1 (failed) result set:
Column Name |
Data type |
Describe |
Index_name |
sysname |
The index name. |
Index_description |
varchar (210) |
The index description. |
Index_keys |
nvarchar (2078) |
A table or view column that constructs an index on these columns. |
Columns that are indexed in descending order are listed in the result set with a minus sign (-) followed by the name of the column (which is the default) when the column is listed in the ascending index. Note This information is displayed in the sp_helpindex result set if the index has been set with the NoRecompute option of UPDATE STATISTICS.
There are those indexes in the SQL query table