Wednesday, January 19, 2011

How to see Primary key in a table in DB2

---------See primary key with column name in a table in db2---------------
db2  "select constname,tabname,colname from syscat.keycoluse where tabname='TABLENAME' "

It will give you.....

Example:::  

db2inst1@confonet:~> db2 "select constname,tabname,colname from syscat.keycoluse where tabname='COMPLAINANT_RESPONDENT'"

--------------Output--------------------------------
CONSTNAME                                                                                                                        TABNAME                                                                                                                          COLNAME                                                                                                             
-------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------
SQL100416165400090                                                                                                               COMPLAINANT_RESPONDENT                                                                                                           CRSEQ                                                                                                               
SQL100416165400090                                                                                                               COMPLAINANT_RESPONDENT                                                                                                           CR_TYPE                                                                                                             
SQL100416165400090                                                                                                               COMPLAINANT_RESPONDENT                                                                                                           FANO                                                                                                                

  3 record(s) selected.
==========================================================

Here COMPLAINANT_RESPONDENT table have a composite primary key on three column (FANO,CRSEQ,CR_TYPE)

No comments:

Post a Comment