Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 151003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:22:50+00:00 2026-05-11T09:22:50+00:00

SELECT sysobjects.xtype, syscolumns.name, sysindexkeys.indid, sysobjects.type FROM syscolumns LEFT JOIN sysobjects ON syscolumns.id = sysobjects.id

  • 0
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] ] 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:22:51+00:00Added an answer on May 11, 2026 at 9:22 am

    That seems correct to me, your index has 2 columns, user_id has position 1 and config_name has position 2

    From BOL keyno: Position of the column in the index

    why do you think they would both be 1?

    Here you go, you needed to join back to the sysobject table but on the index not the table itself

    SELECT s2.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 ) join sysobjects s2 on s2.parent_obj = sysindexkeys.id WHERE sysobjects.name = '{$table}' and s2.type = 'K' AND sysindexkeys.indid IS NOT NULL ORDER BY sysindexkeys.indid, sysindexkeys.keyno 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

IF EXISTS (SELECT name FROM sysobjects WHERE name = 'myTrigger' AND type = 'TR')
If I run the following script SELECT so.Name, sc.Text FROM syscomments sc JOIN sysobjects
I've picked up some SQL similar to the following: IF EXISTS(SELECT name FROM tempdb..sysobjects
I use this command to drop a table in sql-server 2008 IF EXISTS(SELECT name
SELECT events.title FROM events ORDER BY events.title DESC I'm getting the proper ordering for
select @result=@input.query('*') for xml raw,type Above statement will generate following alert: Msg 6819, Level
SELECT sum(TotalHoursM) + (TotalHoursT) + (TotalHoursW) + (TotalHoursTH) + (TotalHoursF) AS TOTAL FROM LeaveRequest
SELECT (SELECT IIF(IsNull(sum(b.AmountCharged) - sum(b.AmountPaid)), a.Balance, (sum(b.AmountCharged) - sum(b.AmountPaid))) FROM tblCurrentTransaction AS b WHERE
SELECT AVG(variable) AS Expr1, SUM(variable) AS Expr2 FROM ...... result for AVG is 2,
SELECT * FROM menu WHERE item_id = 1 OR item_id = 2 OR item_id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.