kingbase查看表的详细信息(字段、字段注释、长度、是否为主键、小数位数、是否为空)

SELECT
   A.ordinal_position,
   A.column_name,
   CASE A.is_nullable WHEN 'NO' THEN 0 ELSE 1 END AS is_nullable,
   A.data_type,
   coalesce(A.character_maximum_length, A.numeric_precision, -1) as length,
   A.numeric_scale,
        CASE WHEN length(B.attname) > 0 THEN 1 ELSE 0 END AS is_pk,E.comment
FROM
   information_schema.columns A 
LEFT JOIN (
    SELECT
        sys_attribute.attname
    FROM
        sys_index,
        sys_class,
        sys_attribute
        
    WHERE
        sys_class.oid = '表名' :: regclass
    AND sys_index.indrelid = sys_class.oid
    AND sys_attribute.attrelid = sys_class.oid
    AND sys_attribute.attnum = ANY (sys_index.indkey)
) B ON A.column_name = b.attname
LEFT JOIN (
SELECT DISTINCT a.attname AS field,  b.description AS comment
FROM sys_class c, sys_attribute a
    LEFT JOIN sys_description b
    ON  (select min(oid) from sys_class where relname='表名') = b.objoid
        AND a.attnum = b.objsubid, sys_type t
WHERE c.relname = '表名'
    AND a.attnum > 0
    AND a.attrelid = c.oid
    AND a.atttypid = t.oid
) E ON E.field = A.column_name

WHERE

   A.table_schema = '模式名'
AND A.table_name = '表名'
ORDER BY
   ordinal_position ASC;
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值