Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Location
    FRANCE
    Posts
    393

    Unanswered: Name of primary key

    What 's the way to know
    the name of the column that is
    the primary key of a table

  2. #2
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621
    Try this one:

    select 'Table ['+su.name+'.'+so.name+']',sc.name
    from sysindexes sy
    join sysobjects so on so.id=sy.id and so.xtype='U'
    join sysusers su on su.uid=so.uid
    join sysindexkeys si on si.id=so.id and si.indid=sy.indid
    join syscolumns sc on sc.id=so.id and sc.colid=si.colid
    join sysobjects sop on sop.parent_obj=so.id and sop.xtype='PK' and sop.name=sy.name
    where sy.indid not in(0,255)

  3. #3
    Join Date
    Nov 2003
    Location
    FRANCE
    Posts
    393
    Thank you

    forgot that existed sysindexes

  4. #4
    Join Date
    Nov 2003
    Location
    FRANCE
    Posts
    393
    Thank you very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •