PostgreSql查看当前表的主外键关系

时间:2022-02-14 12:22:33

PostgreSql查看当前表被哪些引用作参考表

-- pg_CONSTRAINT.contype : p(主键), f(外键), u(唯一), c(检查)
-- 查看当前表ID
SELECT oid, relname FROM pg_class WHERE relname = 'syslogfilter';
-- 查看引用当前表ID作参考表的主外键约束信息
SELECT * FROM pg_CONSTRAINT WHERE confrelid = '24935';
-- 查看那些外键的名称
SELECT oid, relname FROM pg_class WHERE oid in
(
SELECT conrelid FROM pg_CONSTRAINT WHERE confrelid = '24935'
);