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='表名称';
相关推荐
像风一样自由20204 小时前
23.OCR在知识库中的作用扫描件和图片文字如何进入RAG
postgresql·大模型·ocr·rag
刃神太酷啦6 小时前
Redis 进阶核心:持久化 (RDB/AOF)、事务与主从复制全解析----《Hello Redis!》(5)
linux·c语言·数据库·c++·redis·缓存·bootstrap
丁丁点灯o6 小时前
Oracle中使用外键的场景及不适用外键的情况
数据库·oracle
天天进步20156 小时前
Pixelle-Video 源码解析 #18:声音克隆功能:参考音频如何影响解说效果?
数据库·音视频
不懂的浪漫7 小时前
ToDesk 连接 Linux 后分辨率过低的解决方法
linux·运维·数据库
布莱克6057 小时前
Redis 详解:从核心数据结构到高可用架构
数据库
冰暮流星8 小时前
mysql之左外连接与右外连接
数据库·sql
jyOverQ8 小时前
MySQL 联合索引怎么用?最左匹配原则到底是什么意思?
数据库·mysql
oradh8 小时前
Oracle enq: US - contention 等待事件总结
数据库·oracle
姚不倒9 小时前
etcd 学习系列(一):从业务需求出发,理解 etcd 是什么
运维·数据库·etcd