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 7879829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:59:33+00:00 2026-06-03T03:59:33+00:00

I am working on a page where we need to visually compare the schema

  • 0

I am working on a page where we need to visually compare the schema of same table across the two database-one in sql server and other in mysql.I have to include indexes as well.

now mysql query shows info along with indexes –

select column_name,column_type,table_name,column_key 
  from INFORMATION_SCHEMA.COLUMNS where table_name = 'tbl_ClientDN'

But for sql server the same query does not return indexes-

 select * from INFORMATION_SCHEMA.COLUMNS where table_name = 'tbl_ClientDN'

so i need query to compbine the result of –

 sp_helpindex 'tbl_ClientDN'

how to get column_key showing indexes in mssql query.
any suggestion ?

  • 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. Editorial Team
    Editorial Team
    2026-06-03T03:59:34+00:00Added an answer on June 3, 2026 at 3:59 am

    Stay away from INFORMATION_SCHEMA.COLUMNS, especially for indexes, since things like filtered indexes and included columns are not part of the definition. I talk about this in more detail here:

    • The case against INFORMATION_SCHEMA views

    You want to use sys.indexes and sys.index_columns for this. For example:

    DECLARE @tablename NVARCHAR(512) = 'dbo.tbl_ClientDN';
    
    SELECT
        [Index]  = i.name,
        [Column] = c.Name, 
        [Type]   = i.type_desc,
        PK = i.is_primary_key,
        [Unique] = i.is_unique,
        [Unique Constraint] = i.is_unique_constraint,
        [DESC] = ic.is_descending_key,
        [INCLUDE] = ic.is_included_column,
        [Filtered] = i.filter_definition -- only for SQL Server 2008+
    FROM
        sys.indexes AS i 
    INNER JOIN 
        sys.index_columns AS ic 
        ON i.[object_id] = ic.[object_id] 
        AND i.index_id = ic.index_id
    INNER JOIN 
        sys.columns c
        ON ic.column_id = c.column_id
        AND ic.[object_id] = c.[object_id]
    WHERE 
        i.[object_id] = OBJECT_ID(@tablename)
    ORDER BY [Index], ic.index_column_id;
    

    If you want to do this for all tables at once, then simple changes:

    SELECT
        [Table] = QUOTENAME(OBJECT_SCHEMA_NAME(i.[object_id]))
          + '.' + QUOTENAME(OBJECT_NAME(i.[object_id])),
        [Index]  = i.name,
        [Column] = c.Name, 
        [Type]   = i.type_desc,
        PK = i.is_primary_key,
        [Unique] = i.is_unique,
        [Unique Constraint] = i.is_unique_constraint,
        [DESC] = ic.is_descending_key,
        [INCLUDE] = ic.is_included_column,
        [Filtered] = i.filter_definition -- only for SQL Server 2008+
    FROM
        sys.indexes AS i 
    INNER JOIN 
        sys.index_columns AS ic 
        ON i.[object_id] = ic.[object_id] 
        AND i.index_id = ic.index_id
    INNER JOIN 
        sys.columns c
        ON ic.column_id = c.column_id
        AND ic.[object_id] = c.[object_id]
    ORDER BY [Table], [Index], ic.index_column_id;
    

    More information available in the topics sys.indexes and sys.index_columns.

    You also might want to take a look at Kimberley L. Tripp’s sp_helpindex2.


    EDIT

    In general I agree with @BrianWhite’s comment. If you are spending any effort on this at all, you should be using a tool for this instead of re-inventing the wheel and trying to write it yourself. Troubleshooting this one query you’ve probably already spent, in terms of time, the cost of a good tool. Please read this post:

    • The cost of reinventing the wheel
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a product page and need to create two separate galleries
I'm working on a page where I need to associate a list of objects
I am working on an HTML page where i need to send confirmation by
i am working a on a permission system. In each page it will need
I'm working on a FBML fan page for a client. I need to perform
I am working on .aspx page that uses a t-sql query that uses a
I am working on ajax-page using PageMethods (web service) to interact with server. I
I'm working with a page that has several links that contain the same href
I am working on a page where I need to highlight different events in
I'm working on a page where there's about 6 divs with the same class

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.