- 论坛徽章:
- 7
|
如果有多个外键,你要搞清楚到底要查哪个外键
我举的例子就是有两个外键- create table t(a int primary key, b int, c int, d int);
- create table t1(a int primary key, b int, c int, d int);
- create table s(a1 int references t(a), a2 int references t1(a), a3 int);
- postgres=# select conname from pg_constraint where contype = 'f' and conrelid = (select oid from pg_class where relname = 's');
- conname
- -----------
- s_a1_fkey
- s_a2_fkey
- (2 rows)
- postgres=# \d s
- Table "public.s"
- Column | Type | Modifiers
- --------+---------+-----------
- a1 | integer |
- a2 | integer |
- a3 | integer |
- Foreign-key constraints:
- "s_a1_fkey" FOREIGN KEY (a1) REFERENCES t(a)
- "s_a2_fkey" FOREIGN KEY (a2) REFERENCES t1(a)
复制代码 回复 10# stone531
|
|