TSQL to get clustered index information in SQL Server 2005

Published 10 March 08 01:00 AM | SQL Master 

Recently within a supportal case with CSS we have been given the following TSQL to get information on indexes, where I have modified a bit to get 'Clustered' index information alone that was helpful to  see which tables lack of clustered index alone.

 

declare @tablename sysname;
Set @tablename = '<TableName>';

@tablename sysname;
Set @tablename = '<TableName';

with cte (index_name,column_name, index_type) as (cte (index_name,column_name, index_type) as

(select i.name , c.name , case when i.index_id = 1 then 'clustered' else 'non clustered' end

select i.name , c.name , case when i.index_id = 1 then 'clustered' else 'non clustered' end

from sys.index_columns ic join sys.columns c on ic.object_id = c.object_id

 

from sys.index_columns ic join sys.columns c on ic.object_id = c.object_id on ic.object_id = c.object_id and ic.column_id = c.column_id

join sys.indexes i on i.object_id = ic.object_id and ic.column_id = c.column_id

join sys.indexes i on i.object_id = ic.object_id

 

join sys.indexes i on i.object_id = ic.object_idon i.object_id = ic.object_id and i.index_id = ic.index_id

where i.index_id>0 and i.object_id=object_id(@tablename) ), and i.index_id = ic.index_id

where i.index_id>0 and i.object_id=object_id(@tablename) ),

where i.index_id>0 and i.object_id=object_id(@tablename) ),),

cte1 (index_name_cte1) as ((index_name_cte1) as

(( select index_name from cte where column_name in ('')

select index_name from cte where column_name in ('')

from cte where column_name in (''group by index_name ),

 

group by index_name ),), cte2 (index_name_include) as(index_name_include) as

(( select index_name from cte except

 

select index_name from cte except

 

from cte except except

select index_name_cte1 from cte1 )

 

select index_name_cte1 from cte1 )

 

from cte1 ))

select index_name_include,column_name from (select index_name_include,column_name from ((

select cte2.index_name_include, (select top 1 index_type from cte where index_name = cte2.index_name_include ) as index_type from cte2

) as D1 join cte on D1.index_name_include = cte.index_name where D1.index_type = 'clustered';

 

select cte2.index_name_include, (select top 1 index_type from cte where index_name = cte2.index_name_include ) as index_type from cte2

) as D1 join cte on D1.index_name_include = cte.index_name where D1.index_type = 'clustered';

 

) as D1 join cte on D1.index_name_include = cte.index_name where D1.index_type = 'clustered'; where D1.index_type = 'clustered';

 

Comments

# SQL Server Transact-SQL (SSQA.net) : TSQL to get clustered index information in SQL Server 2005 said on March 10, 2008 1:07 AM:

PingBack from http://sqlserver-qa.net/blogs/t-sql/archive/2008/03/10/3741.aspx

# Other SQL Server Blogs around the Web said on March 10, 2008 2:45 AM:

Recently within a supportal case with CSS we have been given the following TSQL to get information on

# http://sqlserver-qa.net/blogs/t-sql/archive/2008/03/10/3741.aspx said on April 4, 2008 6:24 AM:

PingBack from http://frankthefrank.info/entry.php?id=kwws%3d22vtovhuyhu0td1qhw2eorjv2w0vto2dufklyh2533%3b23624326%3a741dvs%7b

Anonymous comments are disabled

About SQL Master

**__________________________________** SQL Server MVP, Sr. DBA & industry expert. - Knowledge is of two kinds. We know a subject ourselves or we know where we can find information on it. It is also a power and you will gain by sharing it.

Search

Go

This Blog

«March 2008»
SMTWTFS
2425262728291
2345678
9101112131415
16171819202122
23242526272829
303112345

Syndication