To get Table and column name for Primary Keys.

  • Mohit Nayyar

    Ten Centuries

    Points: 1008

    Comments posted to this topic are about the item To get Table and column name for Primary Keys.

    Thanks
    Mohit Nayyar
    http://mohitnayyar.blogspot.com/
    "If I am destined to fail, then I do have a purpose in my life, To fail my destiny"

  • artvanhecke

    Grasshopper

    Points: 13

    Sorry for the three year old reply,

    You are right, it is a bit complicated. Your method may not return the columns in the correct order. Might I suggest:

    USE Case_Management

    SELECT o.name, c.name

    FROM sysindexes ix

    JOIN sysobjects o ON ix.id = o.id

    JOIN sysobjects pk ON ix.name = pk.name

    AND pk.parent_obj = ix.id

    AND pk.xtype = 'PK'

    JOIN sysindexkeys ixk on ix.id = ixk.id

    AND ix.indid = ixk.indid

    JOIN syscolumns c ON ixk.id = c.id

    AND ixk.colid = c.colid

    WHERE o.name = 'MAIL_MESSAGES'

    ORDER BY ixk.keyno

    Art

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply