SELECT sysobjects.xtype, syscolumns.name, sysindexkeys.indid, sysobjects.type
FROM
syscolumns
LEFT JOIN sysobjects ON syscolumns.id = sysobjects.id
LEFT JOIN sysindexkeys ON (
syscolumns.id = sysindexkeys.id AND syscolumns.colid = sysindexkeys.colid
)
WHERE sysobjects.name = '{$table}'
AND sysindexkeys.indid IS NOT NULL
ORDER BY sysindexkeys.indid, sysindexkeys.keyno
I'm actually using the following query in order to retreive the column name and the keyno.
The problem is my table has 3 fields:
user_id
config_name
config_value
With a primary key on user_id AND config_name.
I would expect to get the collection:
[
['name' => 'user_id', 'keyno' => 1],
['name' => 'config_name', 'keyno' => 1]
]
But i get :
[
['name' => 'user_id', 'keyno' => 1],
['name' => 'config_name', 'keyno' => 2]
]
What am I doing wrong?
edit: I get the same weirdos results using a two index table
table: project_image_id project_id project_image_src
PK on project_image_id AND unique index on project_id AND project_image_src
Expected:
[
['name' => 'project_image_id', 'keyno' => 1],
['name' => 'project_id', 'keyno' => 2]
['name' => 'project_image_src', 'keyno' => 2]
]
But i get :
[
['name' => 'project_image_id', 'keyno' => 1],
['name' => 'project_id', 'keyno' => 1]
['name' => 'project_image_src', 'keyno' => 2]
]