Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2009
    Posts
    26

    Unanswered: How to get Primary keys of a table in DB2

    Hello everyone,
    I am trying to get the primary keys of a table in DB2

    I tried with this query
    "select t.TABSCHEMA,t.TABNAME, k.colseq, k.colname from syscat.keycoluse k, syscat.tabconst t where k.constname = t.constname and k.tabname = t.tabname and k.TABSCHEMA = t.TABSCHEMA and t.type='P'and t.TABSCHEMA NOT LIKE 'SYS%' AND t.TABLESCHEMA='HERNESS' AND t.TABLNAME='ACCOUNT'";

    but it gives me back the table name,shcmeaname with the primary keys.

    I need a query where i wanted to give the table name and schema name and I should be able to get the primary keys

    I tried searching in google but did not find the correct query .
    By the way i new to DB2.

    So i am looking for a query where i can give the table name and schema name i should be able to get the primary keys of that table.
    I would really appreciate if some one can help me out in this.
    Thanks in advance
    Regards,
    swati

  2. #2
    Join Date
    Mar 2006
    Location
    Tuticorin, India
    Posts
    103
    Try this one
    db2 -x "SELECT A.COLSEQ, A.COLNAME FROM SYSCAT.KEYCOLUSE A, SYSCAT.TABCONST B WHERE A.CONSTNAME=B.CONSTNAME AND B.TYPE='P' AND A.TABNAME='$TABNAME' AND A.TABSCHEMA='$SCHEMANAME' order by A.COLSEQ"

Posting Permissions

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