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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to get index info using information_schema

Author  Topic 

rubs_65
Posting Yak Master

144 Posts

Posted - 2009-04-27 : 13:55:56
Hi,

We are using sys.objects and sys.indexes to get information on indexes and wondering how to get same information using information_Schema views. For example:

Create table dd (dd int primary key, dd1 int)

alter table dd add constraint uk_dd1 unique nonclustered(dd1)

alter table dd drop constraint uk_dd1

create unique index uk_dd1 on dd(dd1)

select index_id,
INDEXPROPERTY ( i.object_id , i.name, 'IsUnique' ),
INDEXPROPERTY ( i.object_id , i.name, 'IsClustered' ),
INDEXPROPERTY ( i.object_id , i.name, 'IndexFillFactor' ),
CASE
WHEN OBJECTPROPERTY(o.object_id, 'IsPrimaryKey') = 1 then 'PRIMARY'
WHEN OBJECTPROPERTY(o.object_id, 'IsUniqueCnst') = 1 then 'UNIQUE'
ELSE 'INDEX'
END
FROM sys.indexes i
LEFT JOIN sys.objects o ON i.name = o.name AND i.object_id = o.parent_object_id
WHERE i.object_id = object_id('dd')
AND i.name = 'uk_dd1'

Thanks
--rubs


   

- Advertisement -