常用数据库获取表,视图,列,索引信息

一、分页获取数据库用户的所有表

(1)、Oracle,OceanBase(Oracle内核版),DM

使用ALL_TABLES,需要添加当前用户作为查询条件

select a3.* from (select a2.* from  (select  a1.*, rownum rn1 from (
select t1.table_name, t2.comments from ALL_TABLES t1, ALL_TAB_COMMENTS t2 WHERE t1.table_name = t2.table_name and upper(t1.owner) = upper(?)
) a1) a2 where rn1 <= 10 ) a3 where rn1 >= 1;

使用USER_TABLES,直接就可以查到当前用户下的表

select a3.* from (select a2.* from  (select  a1.*, rownum rn1 from (
select t1.table_name, t2.comments from USER_TABLES t1, USER_TAB_COMMENTS t2 WHERE t1.table_name = t2.table_name
) a1) a2 where rn1 <= 10 ) a3 where rn1 >= 1;

(2)、MySQL

select t.* from (select table_name,table_type,TABLE_COMMENT from INFORMATION_SCHEMA.TABLES where upper(table_schema) = upper(?) and table_type = 'BASE TABLE') t limit 1,10;

(3)、gaussdb

select t.* from (select table_name,table_type from INFORMATION_SCHEMA.TABLES where upper(table_catalog) = upper(?) and table_type = 'BASE TABLE') t limit 10 offset 1;

(4)、PostgreSQL

select t.* from (select table_name,table_type from INFORMATION_SCHEMA.TABLES where upper(table_schema) = upper(?) and table_type = 'BASE TABLE') t limit 10 offset 1;

二、分页获取数据库用户的所有视图

(1)、Oracle,OceanBase(Oracle内核版),DM

使用ALL_TABLES,需要添加当前用户作为查询条件

select a3.* from (select a2.* from  (select  a1.*, rownum rn1 from (
select t1.view_name, t2.comments from ALL_VIEWS t1, ALL_TAB_COMMENTS t2 WHERE t1.view_name = t2.table_name and upper(t1.owner) = upper(?)
) a1) a2 where rn1 <= 10 ) a3 where rn1 >= 1;

使用USER_TABLES,直接就可以查到当前用户下的表

select a3.* from (select a2.* from  (select  a1.*, rownum rn1 from (
select t1.view_name, t2.comments from USER_VIEWS t1, USER_TAB_COMMENTS t2 WHERE t1.view_name = t2.table_name
) a1) a2 where rn1 <= 10 ) a3 where rn1 >= 1;

(2)、MySQL

select t.* from (select table_name,table_type,TABLE_COMMENT from INFORMATION_SCHEMA.TABLES where upper(table_schema) = upper(?) and table_type = 'VIEW') t limit 1,10;

(3)、gaussdb

select t.* from (select table_name,table_type from INFORMATION_SCHEMA.TABLES where upper(table_catalog) = upper(?) and table_type = 'VIEW') t limit 10 offset 1;

(4)、PostgreSQL

select t.* from (select table_name,table_type from INFORMATION_SCHEMA.TABLES where upper(table_schema) = upper(?) and table_type = 'VIEW') t limit 10 offset 1;

三、查询数据库用户表的列信息

(1)、Oracle,OceanBase(Oracle内核版),DM

使用ALL_TAB_COLUMNS,需要添加当前用户作为查询条件

select * from ALL_TAB_COLUMNS where upper(table_name) = upper(?) and upper(owner) = upper(?);

使用USER_TAB_COLUMNS,直接就可以查到当前用户下的表

select * from USER_TAB_COLUMNS where upper(table_name) = upper(?);

(2)、MySQL,gaussdb

select * from information_schema.COLUMNS where upper(table_name) = upper(?) and upper(table_schema) = upper(?);

(3)、PostgreSQL

select * from information_schema.COLUMNS where upper(table_name) = upper(?) and upper(table_catalog) = upper(?);

四、获取数据库用户的所有表索引

(1)、Oracle,OceanBase(Oracle内核版),DM

使用ALL_IND_COLUMNS,需要添加当前用户作为查询条件

select * from ALL_IND_COLUMNS where upper(table_name) = upper(?) AND upper(index_owner) = upper(?);

使用USER_IND_COLUMNS,直接就可以查到当前用户下的表

select * from USER_IND_COLUMNS where upper(table_name) = upper(?);

(2)、MySQL

select * from INFORMATION_SCHEMA.STATISTICS where upper(table_name) = upper(?) and upper(table_schema) = upper(?);

(3)、gaussdb,PostgreSQL

select * from pg_indexes t where upper(tablename) = upper(?) and upper(schemaname) = upper(?);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值