软件下载吧文章资讯

分类分类

Postgresql 如何查询表引用或被引用的外键方法

2024-02-05 11:03作者:下载吧

今天更新两个SQL。是用来查询PG中,主表被子表引用的外键,或子表引用了哪个主表的主键。

废话不多说,直接上实验!

CentOS 7 + PG 10

创建两个实验表,test01为主表,test02为子表,test02引用test01中的id列。

test=# create table test01(
test(# id int primary key,
test(# col1 varchar(20)
test(# );
CREATE TABLE

test=# create table test02(
test(# id int primary key,
test(# test01_id int references test01(id),
test(# col1 varchar(20)
test(# );
CREATE TABLE

展开全部

相关文章

说两句网友评论
    我要跟贴
    取消