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='表名称';
相关推荐
Gauss松鼠会1 天前
GaussDB慢sql信息收集和执行计划查看
数据库·sql·gaussdb
FreeBuf_1 天前
AWS服务大规模中断,基础设施故障影响全球企业
网络·数据库·aws
NineData1 天前
NineData 数据库 DevOps 新增支持 PolarDB-X
数据库·devops·数据库管理工具·ninedata·polardb-x·sql审核·sql管理工具
christine-rr1 天前
MySQL数据库管理、DDL、DQL、DML、DCL等总结
linux·数据库·mysql
观望过往1 天前
非关系型数据库(NoSQL)学习指南:从入门到实战
数据库·nosql
Quz1 天前
QML TableView:基于SQLite实现增删改查
数据库·qt·sqlite
JuneXcy1 天前
第2章 数据库系统的核心--数据模型
数据库·mysql·oracle
Ahern_1 天前
崖山数据库安装部署
linux·数据库
斯普信专业组1 天前
Redis集群平滑扩缩容与槽位迁移实战指南
数据库·redis·槽位迁移