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='表名称';
相关推荐
我来整一篇38 分钟前
用Redis的List实现消息队列
数据库·redis·list
加什么瓦1 小时前
Redis——数据结构
数据库·redis·缓存
神仙别闹1 小时前
基于C#+SQL Server开发(WinForm)租房管理系统
数据库·oracle·c#
528301 小时前
MySQL主从复制
数据库·mysql
qq_12498707532 小时前
原生小程序+springboot+vue医院医患纠纷管理系统的设计与开发(程序+论文+讲解+安装+售后)
java·数据库·spring boot·后端·小程序·毕业设计
jie188945758662 小时前
ubuntu----100,常用命令2
数据库·ubuntu
若兰幽竹2 小时前
【HBase整合Hive】HBase-1.4.8整合Hive-2.3.3过程
数据库·hive·hbase
lybugproducer2 小时前
浅谈 Redis 数据类型
java·数据库·redis·后端·链表·缓存
青山是哪个青山2 小时前
Redis 常见数据类型
数据库·redis·bootstrap
廖圣平2 小时前
美团核销 第三方接口供应商 (含接口文档)
开发语言·数据库·php