Friday, March 9, 2012

Metadata: Columns in Indexes


Hi, Do you know if there are any way to know the name of wich columns integrate the indexes?
I have just found a column named "keys" in the table "sysindexes" but it is just a kind of code.

I have a problem with the primary keys that have created,
something similar to the refered: http://support.microsoft.com/kb/262541/en-us

So I am trying to identify which of my indexes would make conflict with the PKs, and
also need to standarize them. Could you help me please?

There are a few ways.

1. In 2000 or earlier, you can use: INDEX_COL, which is a bit annoying, but it works

2. In 2005, use the sys.index_columns view. It gives you a much easier view.

3. In either, for KEY constraints, use the INFORMATION_SCHEMA.KEY_COLUMN_USAGE view.

|||

Thank Louis, Now I am using this query to get the column names of each index,
but just don't know how to compare the columns from one index with the ones that has
the other.

I need to be sure that the columns that I am using as a part of my PK's are not contained exactly as a
part of any Index because that will cause me problems with certain kind of querys used trough my
linked server (because of the bug that I have refered)

select so.name as tabla, si.name as indice, --, si.indid as tipoindice,
sc.name

from sysobjects so,
sysindexes si,
sysindexkeys sik,
syscolumns sc
where so.xtype = 'U'
and si.id = OBJECT_ID(so.name)
and so.id = sik.id
and si.indid = sik.indid
and so.id = sc.id
and sik.colid = sc.colid

and (indexproperty(si.id, si.name, 'IsAutoStatistics') = 0 /*Index was generated by the auto create statistics option of sp_dboption. 1 = True 0 = False NULL = Invalid input)*/
and indexproperty(si.id, si.name, 'IsHypothetical') = 0)
and indexproperty(si.id, si.name, 'IsStatistics') = 0
order by si.indid


Whit this query i get something like this:


Table Index Column
-
Author IX_Author_2 code
Author IX_Author_2 c_branch

Author IX_Author_1 code

Author PK_Author code
Author PK_Author c_branch


So, for example the case of IX_Author_2 and PK_Author will give me a problem and
I need to correct the Indexes but first i need a way to identify them.
I am trying with a cursor but just cannot get the right.
Could anybody give me an idea please.

No comments:

Post a Comment