1、查询表是否存在数据库
select * from information_schema.tables where table_schema='public' and table_type='BASE TABLE' and table_name='表名称';
2、查询表字段信息
select * from information_schema.columns where table_schema='public' and table_name='表名称';
3、查询主键外键
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='表名称';
文章来源地址https://www.toymoban.com/news/detail-817824.html
文章来源:https://www.toymoban.com/news/detail-817824.html
到了这里,关于PostgreSQL教程--数据库查询表是否存在数据库中,表字段信息及主外键的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!