如何查看表的主键和外键对应的字段

可通过以下sql查看表的主键和外键以及对应的字段:

select
o.constrname,
i.idxname,
t.tabname,
 (select c1.colname from syscolumns c1 where c1.colno=abs(i.part1) and o.tabid=c1.tabid) ||
nvl(','||(select c1.colname from syscolumns c1 where c1.colno=abs(i.part2 ) and o.tabid=c1.tabid),'')||
nvl(','||(select c1.colname from syscolumns c1 where c1.colno=abs(i.part3 ) and o.tabid=c1.tabid),'')||
nvl(','||(select c1.colname from syscolumns c1 where c1.colno=abs(i.part4 ) and o.tabid=c1.tabid),'')||
nvl(','||(select c1.colname from syscolumns c1 where c1.colno=abs(i.part5 ) and o.tabid=c1.tabid),'')||
nvl(','||(select c1.colname from syscolumns c1 where c1.colno=abs(i.part6 ) and o.tabid=c1.tabid),'')||
nvl(','||(select c1.colname from syscolumns c1 where c1.colno=abs(i.part7 ) and o.tabid=c1.tabid),'')||
nvl(','||(select c1.colname from syscolumns c1 where c1.colno=abs(i.part8 ) and o.tabid=c1.tabid),'')||
nvl(','||(select c1.colname from syscolumns c1 where c1.colno=abs(i.part9 ) and o.tabid=c1.tabid),'')||
nvl(','||(select c1.colname from syscolumns c1 where c1.colno=abs(i.part10) and o.tabid=c1.tabid),'')||
nvl(','||(select c1.colname from syscolumns c1 where c1.colno=abs(i.part11) and o.tabid=c1.tabid),'')||
nvl(','||(select c1.colname from syscolumns c1 where c1.colno=abs(i.part12) and o.tabid=c1.tabid),'')||
nvl(','||(select c1.colname from syscolumns c1 where c1.colno=abs(i.part13) and o.tabid=c1.tabid),'')||
nvl(','||(select c1.colname from syscolumns c1 where c1.colno=abs(i.part14) and o.tabid=c1.tabid),'')||
nvl(','||(select c1.colname from syscolumns c1 where c1.colno=abs(i.part15) and o.tabid=c1.tabid),'')||
nvl(','||(select c1.colname from syscolumns c1 where c1.colno=abs(i.part16) and o.tabid=c1.tabid),'') collist
from sysconstraints o,sysindexes i,systables t
where o.constrtype in ('P','R')
and o.idxname=i.idxname
and o.tabid=t.tabid
and t.tabname='table_name';