【数据库】四大传统数库据元数据查询

2023-11-01 05:12

本文主要是介绍【数据库】四大传统数库据元数据查询,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、Mysql

-- 查询列信息
select t.table_catalog,t.table_schema,t.table_name,t.table_type,table_rows
,column_name,ordinal_position,column_default,is_nullable,data_type,character_maximum_length,numeric_precision,numeric_scale,datetime_precision,column_type,character_set_name,collation_name
from `information_schema`.`tables` t 
inner join `information_schema`.`columns` c 
on t.table_catalog=c.table_catalog and t.table_schema=c.table_schema and t.table_name=c.table_name
where 1=1
and t.table_schema='test' 
and t.table_name='test_type_meta_basic';-- 查询索引信息
show index from test.test_type_meta_basic;-- 查询表的约束
select t.constraint_schema,t.table_name,t.constraint_name,t.constraint_type ,group_concat(c.column_name order by ordinal_position) column_names
from `information_schema`.`table_constraints` t inner join `information_schema`.`key_column_usage` c on 1=1 
and t.table_schema ='test' 
and t.table_name='test_type_meta_basic' 
and t.table_schema =c.table_schema
and t.table_name=c.table_name
and t.constraint_name =c.constraint_name
group by t.constraint_schema,t.table_name,t.constraint_name,t.constraint_type;

Postgres

-- 查询列信息
select t.table_catalog,t.table_schema,t.table_name,t.table_type
,column_name,ordinal_position,column_default,is_nullable,data_type,character_maximum_length,numeric_precision,numeric_scale,datetime_precision,udt_name
from "information_schema"."tables" t 
inner join "information_schema"."columns" c 
on t.table_catalog=c.table_catalog and t.table_schema=c.table_schema and t.table_name=c.table_name
where t.table_schema='ischema' and t.table_name='test_type_meta_basic';-- 查询索引列
select t.tablename,t.indexname,t.indexdef from "pg_catalog"."pg_indexes" t 
where t.schemaname='ischema' and t.tablename ='test_type_meta_basic' -- 查询表的约束
select t.constraint_schema,t.table_name,t.constraint_name,t.constraint_type ,string_agg(c.column_name,',' order by ordinal_position) column_names
from "information_schema"."table_constraints" t inner join "information_schema"."key_column_usage" c on 1=1 
and t.table_schema ='ischema' 
and t.table_name='test_type_meta_basic' 
and t.table_schema =c.table_schema
and t.table_name=c.table_name
and t.constraint_name =c.constraint_name
group by t.constraint_schema,t.table_name,t.constraint_name,t.constraint_type;

Sqlserver

-- 查询列信息
select t.table_catalog,t.table_schema,t.table_name,t.table_type
,column_name,ordinal_position,column_default,is_nullable,data_type,character_maximum_length,numeric_precision,numeric_scale,datetime_precision,collation_name
from "INFORMATION_SCHEMA"."TABLES" t 
inner join "INFORMATION_SCHEMA"."COLUMNS" c 
on t.table_catalog=c.table_catalog and t.table_schema=c.table_schema and t.table_name=c.table_name
where t.table_schema='ischema' and t.table_name='test_type_meta_basic';-- 查询索引信息
select table_schema,table_name,index_name,index_type,index_type_desc,is_unique,is_primary_key
,string_agg(column_name,',' ) WITHIN GROUP ( ORDER BY key_ordinal ASC)  column_names from (
select s.name table_schema,t.name table_name,c.name column_name
,i.name index_name,i.type index_type,i.type_desc index_type_desc,i.is_unique,i.is_primary_key
,ic.key_ordinal
from sys.schemas s 
inner join "sys"."tables" t on s.schema_id =t.schema_id 
inner join "sys"."indexes" i on t.object_id =i.object_id 
inner join "sys"."index_columns" ic on i.object_id =ic.object_id and i.index_id=ic.index_id
inner join "sys"."columns" c on ic.object_id =c.object_id  and ic.column_id = c.column_id 
where t.name ='test_type_meta_basic'
) tmp group by table_schema,table_name,index_name,index_type,index_type_desc,is_unique,is_primary_key;-- 查询表的约束
select t.constraint_schema,t.table_name,t.constraint_name,t.constraint_type ,string_agg(c.column_name,',') within group (order by ordinal_position) column_names
from "INFORMATION_SCHEMA"."TABLE_CONSTRAINTS" t inner join "INFORMATION_SCHEMA"."KEY_COLUMN_USAGE" c on 1=1 
and t.table_schema ='ischema' 
and t.table_name='test_type_meta_basic' 
and t.table_schema =c.table_schema
and t.table_name=c.table_name
and t.constraint_name =c.constraint_name
group by t.constraint_schema,t.table_name,t.constraint_name,t.constraint_type;

Oracle

-- 查询列信息
select t.OWNER ,t.TABLE_NAME
,COLUMN_NAME,COLUMN_ID,NULLABLE,DATA_TYPE,DATA_PRECISION,DATA_SCALE,CHARACTER_SET_NAME
from "SYS"."ALL_TABLES" t 
inner join "SYS"."ALL_TAB_COLS" c 
ON t.OWNER=c.OWNER and t.TABLE_NAME=c.TABLE_NAME
where t.OWNER ='CDCUSER' and t.TABLE_NAME='TEST_TYPE_META_BASIC' ORDER BY COLUMN_ID;-- 查询索引信息
SELECT TABLE_NAME,INDEX_NAME,LISTAGG(COLUMN_NAME,',') WITHIN GROUP (ORDER BY COLUMN_POSITION) agg 
FROM "ALL_IND_COLUMNS" 
WHERE TABLE_NAME='TEST_TYPE_META_BASIC' AND TABLE_OWNER ='CDCUSER'
GROUP BY TABLE_NAME,INDEX_NAME;-- 查询表的约束
SELECT t.TABLE_NAME ,t.CONSTRAINT_NAME,t.CONSTRAINT_TYPE ,LISTAGG(c.COLUMN_NAME,',') WITHIN GROUP (ORDER BY POSITION) COLUMN_NAMES
FROM ALL_CONSTRAINTS t,ALL_CONS_COLUMNS c 
WHERE t.TABLE_NAME =c.TABLE_NAME 
AND t.OWNER=c.OWNER AND t.CONSTRAINT_NAME=c.CONSTRAINT_NAME 
AND t.OWNER='CDCUSER' AND t.TABLE_NAME='TEST_TYPE_META_BASIC'
GROUP BY t.TABLE_NAME ,t.CONSTRAINT_NAME,t.CONSTRAINT_TYPE;

这篇关于【数据库】四大传统数库据元数据查询的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/320722

相关文章

SpringBoot分段处理List集合多线程批量插入数据方式

《SpringBoot分段处理List集合多线程批量插入数据方式》文章介绍如何处理大数据量List批量插入数据库的优化方案:通过拆分List并分配独立线程处理,结合Spring线程池与异步方法提升效率... 目录项目场景解决方案1.实体类2.Mapper3.spring容器注入线程池bejsan对象4.创建

PHP轻松处理千万行数据的方法详解

《PHP轻松处理千万行数据的方法详解》说到处理大数据集,PHP通常不是第一个想到的语言,但如果你曾经需要处理数百万行数据而不让服务器崩溃或内存耗尽,你就会知道PHP用对了工具有多强大,下面小编就... 目录问题的本质php 中的数据流处理:为什么必不可少生成器:内存高效的迭代方式流量控制:避免系统过载一次性

C#实现千万数据秒级导入的代码

《C#实现千万数据秒级导入的代码》在实际开发中excel导入很常见,现代社会中很容易遇到大数据处理业务,所以本文我就给大家分享一下千万数据秒级导入怎么实现,文中有详细的代码示例供大家参考,需要的朋友可... 目录前言一、数据存储二、处理逻辑优化前代码处理逻辑优化后的代码总结前言在实际开发中excel导入很

MyBatis分页查询实战案例完整流程

《MyBatis分页查询实战案例完整流程》MyBatis是一个强大的Java持久层框架,支持自定义SQL和高级映射,本案例以员工工资信息管理为例,详细讲解如何在IDEA中使用MyBatis结合Page... 目录1. MyBATis框架简介2. 分页查询原理与应用场景2.1 分页查询的基本原理2.1.1 分

Linux下MySQL数据库定时备份脚本与Crontab配置教学

《Linux下MySQL数据库定时备份脚本与Crontab配置教学》在生产环境中,数据库是核心资产之一,定期备份数据库可以有效防止意外数据丢失,本文将分享一份MySQL定时备份脚本,并讲解如何通过cr... 目录备份脚本详解脚本功能说明授权与可执行权限使用 Crontab 定时执行编辑 Crontab添加定

MyBatis-plus处理存储json数据过程

《MyBatis-plus处理存储json数据过程》文章介绍MyBatis-Plus3.4.21处理对象与集合的差异:对象可用内置Handler配合autoResultMap,集合需自定义处理器继承F... 目录1、如果是对象2、如果需要转换的是List集合总结对象和集合分两种情况处理,目前我用的MP的版本

如何通过try-catch判断数据库唯一键字段是否重复

《如何通过try-catch判断数据库唯一键字段是否重复》在MyBatis+MySQL中,通过try-catch捕获唯一约束异常可避免重复数据查询,优点是减少数据库交互、提升并发安全,缺点是异常处理开... 目录1、原理2、怎么理解“异常走的是数据库错误路径,开销比普通逻辑分支稍高”?1. 普通逻辑分支 v

GSON框架下将百度天气JSON数据转JavaBean

《GSON框架下将百度天气JSON数据转JavaBean》这篇文章主要为大家详细介绍了如何在GSON框架下实现将百度天气JSON数据转JavaBean,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录前言一、百度天气jsON1、请求参数2、返回参数3、属性映射二、GSON属性映射实战1、类对象映

Python与MySQL实现数据库实时同步的详细步骤

《Python与MySQL实现数据库实时同步的详细步骤》在日常开发中,数据同步是一项常见的需求,本篇文章将使用Python和MySQL来实现数据库实时同步,我们将围绕数据变更捕获、数据处理和数据写入这... 目录前言摘要概述:数据同步方案1. 基本思路2. mysql Binlog 简介实现步骤与代码示例1

C# LiteDB处理时间序列数据的高性能解决方案

《C#LiteDB处理时间序列数据的高性能解决方案》LiteDB作为.NET生态下的轻量级嵌入式NoSQL数据库,一直是时间序列处理的优选方案,本文将为大家大家简单介绍一下LiteDB处理时间序列数... 目录为什么选择LiteDB处理时间序列数据第一章:LiteDB时间序列数据模型设计1.1 核心设计原则