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

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

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

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

sql 复制代码
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,直接就可以查到当前用户下的表

sql 复制代码
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

sql 复制代码
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

sql 复制代码
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

sql 复制代码
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,需要添加当前用户作为查询条件

sql 复制代码
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,直接就可以查到当前用户下的表

sql 复制代码
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

sql 复制代码
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

sql 复制代码
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

sql 复制代码
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,需要添加当前用户作为查询条件

sql 复制代码
select * from ALL_TAB_COLUMNS where upper(table_name) = upper(?) and upper(owner) = upper(?);

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

sql 复制代码
select * from USER_TAB_COLUMNS where upper(table_name) = upper(?);

(2)、MySQL,gaussdb

sql 复制代码
select * from information_schema.COLUMNS where upper(table_name) = upper(?) and upper(table_schema) = upper(?);

(3)、PostgreSQL

sql 复制代码
select * from information_schema.COLUMNS where upper(table_name) = upper(?) and upper(table_catalog) = upper(?);

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

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

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

sql 复制代码
select * from ALL_IND_COLUMNS where upper(table_name) = upper(?) AND upper(index_owner) = upper(?);

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

sql 复制代码
select * from USER_IND_COLUMNS where upper(table_name) = upper(?);

(2)、MySQL

sql 复制代码
select * from INFORMATION_SCHEMA.STATISTICS where upper(table_name) = upper(?) and upper(table_schema) = upper(?);

(3)、gaussdb,PostgreSQL

sql 复制代码
select * from pg_indexes t where upper(tablename) = upper(?) and upper(schemaname) = upper(?);
相关推荐
2401_8315017338 分钟前
Linux之Zabbix分布式监控篇(二)
数据库·分布式·zabbix
秋林辉2 小时前
Jfinal+SQLite处理 sqlite数据库执行FIND_IN_SET报错
jvm·数据库·sqlite
巴里巴气5 小时前
MongoDB复杂查询 聚合框架
数据库·mongodb
scheduleTTe8 小时前
SQL增查
数据库·sql
浮生带你学Java8 小时前
2025Java面试题及答案整理( 2025年 7 月最新版,持续更新)
java·开发语言·数据库·面试·职场和发展
期待のcode8 小时前
图片上传实现
java·前端·javascript·数据库·servlet·交互
小毛驴8509 小时前
redis 如何持久化
数据库·redis·缓存
吗喽1543451889 小时前
用python实现自动化布尔盲注
数据库·python·自动化
hbrown9 小时前
Flask+LayUI开发手记(十一):选项集合的数据库扩展类
前端·数据库·python·layui
云资源服务商11 小时前
探索阿里云DMS:解锁高效数据管理新姿势
数据库·阿里云·oracle·云计算