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 |
ajh
Starting Member
3 Posts |
Posted - 2011-05-05 : 09:37:28
|
Example 1Schemna name: XYZIndex name : I1Table name : Acolumns name : col1, col2Schema name : PQRIndex name : I8Table name : Acolumns name : col1, col2Query Should Return :Index Name Table Columns I1 A col1 , col2I8 A col1 , col2This means that 2 indexes in 2 different schemas are based on the same columns. I need to identify such indexes so I can then have the same names for all such indexes.Because the index is the same in both schemas for the same table but have different names. The idea is to standardize the indexes.example 2Schemna name: LMNIndex name : I2Table name : Acolumns name : col1, col2Schema name : PQRIndex name : I9Table name : Acolumns name: col1, col2, col3Query should return: Index Name Table Columns I2 A col1 , col2I9 A col1 , col2, col3This means that in different schema's the indexes are actually the same but are based on different number of columns. I need to identfy such indexes and then standardize them in both schemas. |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-05-05 : 09:49:58
|
Indexes are not "in" a schema. Indexes are created on columns in a table. A table is owned by a schema.A better naming convention would be to name the indexes after the columns they include, such as col1_col2 instead of I1. That gives you consistent naming and descriptions of which columns the index contains. |
|
|
ajh
Starting Member
3 Posts |
Posted - 2011-05-06 : 05:23:14
|
i am using this query : select distinct sk.column_name, sk.index_name, si.table_schemafrom qsys2.syskeys sk , qsys2.syskeys sk1, qsys2.sysindexes siwhere sk.column_name = sk1.column_nameand sk.index_name != sk1.index_nameand si.index_schema = sk.index_schemaand si.table_schema in('ZDBXINV004','ZDBXDEMO4')and si.table_name = 'TAUDITTRAILDETAIL'order by 3;Output I am getting is not what i want.Sample Data taken from sysindexes and syskeys.TABLE_NAME || COLUMN_NAME || INDEX_NAME || SCHEMAT1 || C1 || IDX1 || AT1 || C1 || IDX2 || B Output desired is :TABLE_NAME || COLUMN_NAME T1 || C1All other being the same only the index name is different. We conclude by looking at this that in schema B IDX2 is actually IDX1 of schema A.By identifying such indexes based on similar columns i will replace the name of IDX2 to IDX1. There are many such indexes which have different names.Kindly guide please. |
|
|
|
|
|
|
|