Unanswered: How to get Primary keys of a table in DB2
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
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"