title: Query to fetch MsSQL table unique index and primary keys
body: <pre><code>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
  </code></pre>
  
  <p>I'm actually using the following query in order to retreive the column name and the keyno.</p>
  
  <p>The problem is my table has 3 fields:</p>
  
  <pre><code>user_id
  config_name
  config_value
  </code></pre>
  
  <p>With a primary key on user_id AND config_name.</p>
  
  <p>I would expect to get the collection:</p>
  
  <pre><code>[
    ['name' =&gt; 'user_id', 'keyno' =&gt; 1],
    ['name' =&gt; 'config_name', 'keyno' =&gt; 1]
  ]
  </code></pre>
  
  <p>But i get :</p>
  
  <pre><code>[
    ['name' =&gt; 'user_id', 'keyno' =&gt; 1],
    ['name' =&gt; 'config_name', 'keyno' =&gt; 2]
  ]
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p><strong>edit:</strong> 
  I get the same weirdos results using a two index table</p>
  
  <p>table:
      project_image_id
      project_id
      project_image_src</p>
  
  <p>PK on project_image_id AND unique index on project_id AND project_image_src</p>
  
  <p>Expected:</p>
  
  <pre><code>[
    ['name' =&gt; 'project_image_id', 'keyno' =&gt; 1],
    ['name' =&gt; 'project_id', 'keyno' =&gt; 2]
    ['name' =&gt; 'project_image_src', 'keyno' =&gt; 2]
  ]
  </code></pre>
  
  <p>But i get :</p>
  
  <pre><code>[
    ['name' =&gt; 'project_image_id', 'keyno' =&gt; 1],
    ['name' =&gt; 'project_id', 'keyno' =&gt; 1]
    ['name' =&gt; 'project_image_src', 'keyno' =&gt; 2]
  ]
  </code></pre>