获取业务库的schema信息导出成数据字典

获取业务库的schema信息导出成数据字典

场景:需要获取业务库的schema信息导出成数据字典,以下为获取oracle与mysql数据库的schema信息语句


--获取oracle库schema信息
select
  tt1.owner as t_owner
 ,tt1.table_name
 ,tt1.column_name
 ,tt1.data_type
 ,tt1.data_length
 ,tt1.nullable
 ,tt1.comments
 ,tt1.column_id
 ,tt2.pkcols
from
(
 select
        atc.owner
       ,atc.table_name
       ,atc.column_name
       ,atc.data_type
       ,atc.data_length
       ,atc.nullable
       ,acc.comments
       ,atc.column_id
 from all_tab_columns atc
 join all_col_comments acc
 on atc.table_name=acc.table_name
    and atc.owner=acc.owner
    and atc.column_name=acc.column_name
) tt1
left join

(
 SELECT OWNER,table_name,LISTAGG(column_name,',') WITHIN group(ORDER BY column_name) AS pkcols
 FROM
 (
 select a.OWNER,a.table_name,a.column_name
 from all_cons_columns a
 join all_constraints b
 on a.constraint_name = b.constraint_name
 and a.OWNER=b.OWNER
 and b.constraint_type = 'P'
 ) t1
 GROUP BY OWNER,table_name
)tt2
on tt1.OWNER=tt2.OWNER
and tt1.table_name=tt2.table_name
order by tt1.owner,tt1.table_name, tt1.column_id;


--获取mysql库schema信息
select
  tt1.table_schema as t_owner
 ,tt1.table_name
 ,tt1.column_name
 ,tt1.data_type
 ,tt1.character_maximum_length
 ,tt1.is_nullable
 ,tt1.column_comment
 ,tt1.ordinal_position
 ,tt2.pkcols
from information_schema.COLUMNS tt1
left join
(
 select
 CONSTRAINT_SCHEMA,table_name,group_concat(column_name order by ordinal_position separator ',') as pkcols
 from information_schema.key_column_usage t
 where constraint_name='PRIMARY'
 group by CONSTRAINT_SCHEMA,table_name
)tt2
on tt1.table_schema=tt2.CONSTRAINT_SCHEMA
and tt1.table_name=tt2.table_name
order by tt1.table_schema,tt1.table_name, tt1.ordinal_position





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值