PostgreSQL教程--数据库查询表是否存在数据库中,表字段信息及主外键

1、查询表是否存在数据库

sql 复制代码
select * from information_schema.tables where table_schema='public' and table_type='BASE TABLE' and table_name='表名称';

2、查询表字段信息

sql 复制代码
select * from information_schema.columns where table_schema='public' and table_name='表名称';

3、查询主键外键

sql 复制代码
select kcu.table_schema,
       kcu.table_name,
       tco.constraint_name,
       kcu.ordinal_position as position,
       kcu.column_name as key_column,
             tco.constraint_type
from information_schema.table_constraints tco
join information_schema.key_column_usage kcu 
     on kcu.constraint_name = tco.constraint_name
     and kcu.constraint_schema = tco.constraint_schema
     and kcu.constraint_name = tco.constraint_name
where kcu.table_schema='public' and 
         kcu.table_name='表名称';
相关推荐
啥都想学的又啥都不会的研究生20 分钟前
Redis设计与实现-服务器中的数据库
运维·服务器·数据库·redis·笔记·缓存·性能优化
m0_7482299920 分钟前
redis 使用
数据库·redis·缓存
Foolforuuu25 分钟前
什么样的场景适用redis?redis缓存是什么?
数据库·redis·缓存
m0_7482340828 分钟前
redis 清理缓存
数据库·redis·缓存
智享AI35 分钟前
阿里云工作空间与Ollama(一)
数据库·阿里云·云计算
聆风吟º35 分钟前
阿里云操作系统控制台实战评测:提升云资源管理与监控效率
数据库·阿里云·云计算
小馒头学python36 分钟前
【阿里云】操作系统控制台——体验与测评
数据库·redis·阿里云
运维小文1 小时前
PQL查询和监控各类中间件
数据库·云原生·中间件·prometheus·监控
网安墨雨1 小时前
信息安全意识之安全组织架构图
数据库·安全·php
补三补四1 小时前
Yashan DB 实例管理
数据库·oracle