Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Bill_C
Constraint Violating Yak Guru
299 Posts |
Posted - 2009-07-29 : 03:10:57
|
| HiIs there a way of listing all Indexes on a table which also lists the INCLUDE list?e.g. I have Indexes on my tables like this:-CREATE NONCLUSTERED INDEX [index1234] ON [dbo].[table1] ( [PCode] ASC)INCLUDE ( [ERecno],[ADate],[Postcode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]Does anyone know how to do this please?Thanks |
|
|
Bill_C
Constraint Violating Yak Guru
299 Posts |
Posted - 2009-07-29 : 03:48:18
|
| I have this script:SELECT OBJECT_NAME (ss.OBJECT_ID ) AS TABLE_NAME,COALESCE (si.type_desc, '***NO INDEX***' ) AS INDEX_TYPE,CASE si.is_unique WHEN 1 THEN 'Y' ELSE 'N' END AS UNIQUE_INDEX,CASE si.is_primary_key WHEN 1 THEN 'Y' ELSE 'N' END AS PRIMARY_KEY,CASE si.is_unique_constraint WHEN 1 THEN 'Y' ELSE 'N' END AS UNIQUE_CONSTRAINT,ss.name AS STATISTIC_NAME,CASE WHEN si.name IS NOT NULL THEN STATS_DATE (t.OBJECT_ID , si.index_id)ELSE STATS_DATE (t.OBJECT_ID , ss.stats_id)END as LAST_UPDATE_STATS,STUFF ((SELECT ', ' + c.nameFROM sys.stats_columns AS scINNER JOIN sys.columns AS cON sc.OBJECT_ID = c.OBJECT_ID AND sc.column_id = c.column_idWHERE ss.OBJECT_ID = sc.OBJECT_ID AND ss.stats_id = sc.stats_idORDER BY c.column_id FOR XML PATH('')), 1, 1, '') AS INDEX_COLUMNS,CASE auto_created WHEN 1 THEN 'Y' ELSE 'N' END AS STAT_AUTO_CREATED,CASE user_created WHEN 1 THEN 'Y' ELSE 'N' END AS STAT_CREATED_BY_USERFROM sys.stats AS ssinner join sys.tables AS tON OBJECT_NAME (ss.OBJECT_ID ) = t.nameLEFT OUTER JOIN sys.indexes AS siON ss.name = si.nameWHERE t.is_ms_shipped = 0--AND auto_created <> 1 --comment out this line to include stats auto created by SQL SERVERORDER BY t.name, COALESCE (si.index_id, 999)which will give me most of the info, but it still does not list all the fields in the INCLUDE statement above?How can I add them in as well? I can't find reference to them anywhere? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-07-30 : 14:07:53
|
| sp_helpindexes 'your table' |
 |
|
|
|
|
|
|
|