Names of columns in the Primary Key

  • How do I get the names of all the columns in the primary key using TSQL in a form I can loop round with a cursor.

    Assume I know how to get the table id from sysobjects and the column names from syscolumns (and I know I shouldn't really be using the system tables!)?

     

     

  • sp_pkeys @table_name =  'YourTableName'


    * Noel

  • See the catalog views in the master database owned by the special "user" INFORMATION_SCHEMA

    For primary keys, see view INFORMATION_SCHEMA.KEY_COLUMN_USAGE

    SQL = Scarcely Qualifies as a Language

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

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