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='表名称';
相关推荐
喵叔哟3 小时前
67.【.NET8 实战--孢子记账--从单体到微服务--转向微服务】--新增功能--分摊功能总体设计与业务流程
数据库·微服务·架构
tryCbest3 小时前
Oracle查看存储过程
数据库·oracle
咩咩不吃草3 小时前
【MySQL】表和列、增删改查语句及数据类型约束详解
数据库·mysql·语法
不懒不懒3 小时前
【MySQL 实战:从零搭建规范用户表(含完整 SQL 与避坑指南)】
数据库
ID_180079054733 小时前
Python结合淘宝关键词API进行商品价格监控与预警
服务器·数据库·python
数据知道3 小时前
PostgreSQL 故障排查:万字详解如何找出数据库中的死锁
数据库·postgresql
AI_56783 小时前
阿里云OSS成本优化:生命周期规则+分层存储省70%
运维·数据库·人工智能·ai
choke2333 小时前
软件测试任务测试
服务器·数据库·sqlserver
龙山云仓3 小时前
MES系统超融合架构
大数据·数据库·人工智能·sql·机器学习·架构·全文检索
IT邦德3 小时前
OEL9.7 安装 Oracle 26ai RAC
数据库·oracle