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='表名称';
相关推荐
Joseit3 小时前
AI应用生成平台:数据库、缓存与存储
数据库·人工智能·缓存
迎風吹頭髮5 小时前
UNIX下C语言编程与实践9-UNIX 动态库创建实战:gcc 参数 -fpic、-shared 的作用与动态库生成步骤
c语言·数据库·unix
黑马金牌编程6 小时前
深入浅出 Redis:从核心原理到运维实战指南一
数据库·redis·缓存·性能优化·非关系型数据库
李迟6 小时前
2025年9月个人工作生活总结
服务器·数据库·生活
野犬寒鸦8 小时前
从零起步学习Redis || 第四章:Cache Aside Pattern(旁路缓存模式)以及优化策略
java·数据库·redis·后端·spring·缓存
茉莉玫瑰花茶9 小时前
Redis - Bitfield 类型
数据库·redis·缓存
lang201509289 小时前
MySQL InnoDB备份恢复全指南
数据库·mysql
爱吃香蕉的阿豪10 小时前
.NET Core 中 System.Text.Json 与 Newtonsoft.Json 深度对比:用法、性能与场景选型
数据库·json·.netcore
mpHH10 小时前
postgresql中的默认列
数据库·postgresql
jllws110 小时前
数据库原理及应用_数据库基础_第4章关系模型的基本理论_数据库完整性规则和MySQL提供的约束
数据库