GBase 8s
其他
文章

GBase 8s 查看库里所有表的表名和主键名

发表于2026-04-21 10:40:2880次浏览9个评论

GBase 8s查看库里所有表的表名和主键名

select  t.tabname,col.colname
from systables t, sysconstraints c,sysindexes i,syscolumns col
where t.tabid = c.tabid 
and t.tabid > 99
and c.constrtype = 'P'
and c.idxname = i.idxname
and t.tabid = col.tabid

评论

登录后才可以发表评论
用户头像
liaosnet发表于 3个月前
可能需要这样写:
select t.tabname,c.constrname,
rtrim((select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part1)) || ',' ||
(select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part2)) || ',' ||
(select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part3)) || ',' ||
(select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part4)) || ',' ||
(select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part5)) || ',' ||
(select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part6)) || ',' ||
(select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part7)) || ',' ||
(select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part8)) || ',' ||
(select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part9)) || ',' ||
(select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part10)) || ',' ||
(select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part11)) || ',' ||
(select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part12)) || ',' ||
(select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part13)) || ',' ||
(select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part14)) || ',' ||
(select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part15)) || ',' ||
(select c.colname from syscolumns c where c.tabid = t.tabid and c.colno = abs(i.part16)), ','
) as pkcollist
from systables t, sysconstraints c,sysindexes i
where t.tabid = c.tabid
and t.tabid > (select tabid from systables where tabname = ' VERSION')
and c.constrtype = 'P'
and c.idxname = i.idxname;
用户头像
路路路发表于 3个月前
@liaosnet:好的,学习了 ~\(≧▽≦)/~
用户头像
柒柒天晴发表于 3个月前
111
用户头像
柒柒天晴发表于 3个月前
学习下
GBase用户19279发表于 3个月前
学习
GBase用户47954发表于 3个月前
感谢作者的精彩分享!
用户头像
郝老师发表于 3个月前
666
曾云林发表于 2个月前
来了
GBase用户51934发表于 2个月前
来了