Results 1 to 4 of 4

Thread: Finding field name of the primary key

  1. #1
    Join Date
    Apr 2005
    Posts
    6

    Finding field name of the primary key

    How can I find the field name of the primary key?

  2. #2
    Join Date
    Mar 2003
    Posts
    468
    for oracle, you could run some sql like this:
    select dc.table_name,dc.constraint_name,
    dcc.column_name, dcc.position
    from dba_constraints dc, dba_cons_columns dcc
    where dc.constraint_type = 'P'
    and dc.constraint_name = dcc.constraint_name
    and dc.table_name = '<table_name>'
    order by dcc.position

  3. #3
    Join Date
    Sep 2002
    Posts
    5,938
    For MS sql, you can try this:

    select CONSTRAINT_NAME, table_name, column_name from information_schema.key_column_usage where CONSTRAINT_NAME like 'pk%'

  4. #4
    Join Date
    Apr 2005
    Posts
    6
    Sorry, I guess I should have specified. I'm using MySQL.

Posting Permissions

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