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='表名称';
相关推荐
tonysh_zds1 小时前
windows pip install pysqlite3 安装失败处理
数据库·sqlite·pip
rising start1 小时前
一、数据库分类及SQLite入门
数据库·sqlite
5***E6857 小时前
【SQL】写SQL查询时,常用到的日期函数
数据库·sql
遇见火星8 小时前
CentOS7 通过源码安装 Redis
数据库·redis·缓存
Mr.朱鹏8 小时前
RocketMQ安装与部署指南
java·数据库·spring·oracle·maven·rocketmq·seata
Coder-coco8 小时前
个人健康管理|基于springboot+vue+个人健康管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·mysql·论文
K哥11258 小时前
【9天Redis系列】基础+全局命令
数据库·redis·缓存
s***46988 小时前
【玩转全栈】----Django模板语法、请求与响应
数据库·python·django
f***R88 小时前
redis分页查询
数据库·redis·缓存
g***72708 小时前
【mysql】导出导入mysql表结构或者数据
数据库·mysql