To get Table and column name for Primary Keys.

  • 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"

  • 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 1 (of 1 total)

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