Informix如何查看表的主键使用了哪些列?

通过sysconstraints只能看到一个{tab_id}_{id}字符串. 无法确认这个主键用了哪些列

阅读 905
1 个回答

写的不太好,欢迎高手指点

select c.colno,c.colname,sc.idxname FROM syscolumns c 
join SYSCONSTRAINTS sc on sc.tabid = c.tabid 
join (
    select idxname,part1 as colno from SYSINDEXES si where tabid=107 and part1 >0
    union all 
    select idxname,part2 as colno from SYSINDEXES si where tabid=107 and part2 >0
    union all
    select idxname,part3 as colno from SYSINDEXES si where tabid=107 and part3 >0
    union all
    select idxname,part4 as colno from SYSINDEXES si where tabid=107 and part4 >0
    union all
    select idxname,part5 as colno from SYSINDEXES si where tabid=107 and part5 >0
    union all
    select idxname,part6 as colno from SYSINDEXES si where tabid=107 and part6 >0
    union all
    select idxname,part7 as colno from SYSINDEXES si where tabid=107 and part7 >0
    union all
    select idxname,part8 as colno from SYSINDEXES si where tabid=107 and part8 >0
    union all
    select idxname,part9 as colno from SYSINDEXES si where tabid=107 and part9 >0
    union all
    select idxname,part10 as colno from SYSINDEXES si where tabid=107 and part10 >0
    union all
    select idxname,part11 as colno from SYSINDEXES si where tabid=107 and part11 >0
    union all
    select idxname,part12 as colno from SYSINDEXES si where tabid=107 and part12 >0
) as t on t.colno = c.colno and t.idxname =sc.idxname 
where c.tabid=107 and sc.constrtype = 'P'
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进