May 11, 2009 at 4:58 pm
Is there any way to find tables that have indexes on computed columns. Any queries for the same? Please advice.
M&M
May 11, 2009 at 5:05 pm
syscolumns has a iscomputed column...the calculation is stored in syscomments if you want to join to get that:
now to get the indexes, that i'm not sure yet....
select object_name(syscolumns.id),
syscolumns.name As CalculatedColumn ,
syscomments.text as TheCalculation
from syscolumns
inner join syscomments on syscolumns.id=syscomments.id
where iscomputed 0
Lowell
May 11, 2009 at 5:15 pm
But is there a way to get the index on a computed column?
M&M
May 11, 2009 at 5:26 pm
this seemed to work for me, but i only had one table with no index:
select distinct object_name(syscolumns.id),
syscolumns.name As CalculatedColumn ,
syscomments.text as TheCalculation,
isnull(object_name(SYSINDEXKEYS.id),'No Index Using This CalculatedColumn') As IndexName
from syscolumns
inner join syscomments on syscolumns.id=syscomments.id
left outer join sysindexes
on syscolumns.id=sysindexes.id
left outer join SYSINDEXKEYS ON sysindexes.ID=SYSINDEXKEYS.ID
AND sysindexes.INDID=SYSINDEXKEYS.INDID
and SYSINDEXKEYS.COLID=SYSCOLUMNS.COLID
where iscomputed 0
Lowell
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply