時間:2024-02-08 11:17作者:下載吧人氣:15
我就廢話不多說了,大家還是直接看實例吧~
postgres=# create table t1(a int primary key,b text,c date);
CREATE TABLE
postgres=# create table t2(a int primary key,b int references t1(a),c text);
CREATE TABLE
postgres=# insert into t1 (a,b,c) values(1,’aa’,now());
INSERT 0 1
postgres=# insert into t1 (a,b,c) values(2,’bb’,now());
INSERT 0 1
postgres=# insert into t2 (a,b,c) values (1,1,’aa’);
INSERT 0 1
postgres=# insert into t2 (a,b,c) values (2,2,’aa’);
INSERT 0 1
postgres=# d t1
Table “public.t1”
Column | Type | Collation | Nullable | Default
——–+———+———–+———-+———
a | integer | | not null |
b | text | | |
c | date | | |
Indexes:
“t1_pkey” PRIMARY KEY, btree (a)
Referenced by:
TABLE “t2” CONSTRAINT “t2_b_fkey” FOREIGN KEY (b) REFERENCES t1(a)
postgres=# d t2
Table “public.t2”
Column | Type | Collation | Nullable | Default
——–+———+———–+———-+———
a | integer | | not null |
b | integer | | |
c | text | | |
Indexes:
“t2_pkey” PRIMARY KEY, btree (a)
Foreign-key constraints:
“t2_b_fkey” FOREIGN KEY (b) REFERENCES t1(a)
postgres=#
網友評論