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='表名称';
相关推荐
~~李木子~~2 小时前
MySQL 迁移总结报告
数据库·mysql
有梦想的攻城狮3 小时前
通过Lettuce实现PB3格式对象在Redis中的存储与查询
数据库·redis·缓存·pb3
桦03 小时前
MySQL【函数】
数据库·mysql
⑩-4 小时前
Redis(1)
数据库·redis·缓存
2301_803554524 小时前
主从同步配置的步骤
数据库
无敌最俊朗@4 小时前
00-7天攻破sqlite数据库(总览sqlite)
数据库·sqlite
Access开发易登软件4 小时前
Access导出带图表的 HTML 报表:技术实现详解
数据库·后端·html·vba·导出·access
_Minato_5 小时前
数据库知识整理——SQL数据定义
数据库·sql·mysql·oracle·database·数据库开发·数据库架构
程序员卷卷狗5 小时前
MySQL 四种隔离级别:从脏读到幻读的全过程
数据库·mysql
l1t5 小时前
改写ITPUB newkid的求解数独DuckDB SQL为Clickhouse格式
数据库·sql·clickhouse·duckdb