Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2004
    Posts
    54

    Unanswered: SQL Stmt to quesry the PK

    is there an sql statement wherein the result would be the
    PK of the table....

    please help, thanks in advance

  2. #2
    Join Date
    Dec 2004
    Posts
    7
    You can use user_constraints,all_constaints or dba_constraints views

    Code:
    SELECT constraint_name FROM user_constraints 
      WHERE table_name='EMP' AND constraint_type='P'

  3. #3
    Join Date
    Oct 2004
    Posts
    54
    jeny, thanks for the help....

  4. #4
    Join Date
    Oct 2004
    Posts
    54
    hhhmmm, just a follow-up question, since the sql statement actually returns the constraint_name, is there a way to return the exact table_name instead... thanks again....

  5. #5
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Type "DESC USER_CONSTRAINTS" and you'll see the full list of columns available to select...

  6. #6
    Join Date
    Oct 2004
    Posts
    54
    if i perform desc user_constraints, then i would get the details of
    the user_constraints, there is no available data wherein the exact
    field name of the primary key would be displayed....

    maybe there is a way for me to JOIN the user_constraints and the
    user_tables so i can also query the exact field name side from the
    constraint name...

    thanks in advance...

  7. #7
    Join Date
    Oct 2004
    Posts
    54
    thanks for all the help, i was able to find the sql statement i'm looking for
    for those interested here it goes....

    select a.constraint_name, a.column_name
    from all_cons_columns a, all_constraints b
    where a.constraint_name = b.constraint_name
    and b.constraint_type = 'P'
    and a.table_name = 'EMP';

Posting Permissions

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