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

作者站长头像
站长
· 阅读数 4

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

回复
1个回答
avatar
test
2024-06-25

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

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'
回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容