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

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

(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(?);
相关推荐
MAGICIAN...3 小时前
【Redis】--持久化机制
数据库·redis·缓存
我真的是大笨蛋3 小时前
JVM调优总结
java·jvm·数据库·redis·缓存·性能优化·系统架构
步步为营DotNet5 小时前
5-2EFCore性能优化
数据库·性能优化·.net
2501_920047035 小时前
Redis-集群
数据库·redis·bootstrap
半夏陌离6 小时前
SQL 拓展指南:不同数据库差异对比(MySQL/Oracle/SQL Server 基础区别)
大数据·数据库·sql·mysql·oracle·数据库架构
旋转的油纸伞6 小时前
SQL表一共有几种写入方式
数据库·sql
半夏陌离6 小时前
SQL 入门指南:排序与分页查询(ORDER BY 多字段排序、LIMIT 分页实战)
java·前端·数据库
isyoungboy6 小时前
SQL高效处理海量GPS轨迹数据:人员gps轨迹数据抽稀实战指南
数据库·sql
敬业小码哥7 小时前
记一次:mysql的json及json数组使用组合使用
数据库·mysql·json
练小杰7 小时前
【Mysql-installer-community-8.0.26.0】Mysql 社区版(8.0.26.0) 在Window 系统的默认安装配置
数据库·sql·mysql·adb·配置文件·mysql安装·关系型数据库