1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
tests=> CREATE TABLE t01(
tests(> chp_t01 int,
tests(> PRIMARY KEY (chp_t01)
tests(> ) WITH OIDS;
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t01_pkey" for table "t01"
CREATE TABLE
tests=> insert into t01 values(3);
INSERT 27496 1
tests=>
tests=> CREATE TABLE t02(
tests(> chp_t02 int,
tests(> PRIMARY KEY (chp_t02)
tests(> ) WITH OIDS;
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t02_pkey" for table "t02"
CREATE TABLE
tests=> insert into t02 values(1);
INSERT 27501 1
tests=>
tests=> CREATE TABLE t1(
tests(> np int REFERENCES t01(chp_t01),
tests(> nt int REFERENCES t02(chp_t02),
tests(> na SERIAL UNIQUE NOT NULL,
tests(> PRIMARY KEY (na,np,nt)
tests(> ) WITH OIDS;
NOTICE: CREATE TABLE will create implicit sequence "t1_na_seq" for serial column "t1.na"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t1_pkey" for table "t1"
NOTICE: CREATE TABLE / UNIQUE will create implicit index "t1_na_key" for table "t1"
CREATE TABLE
tests=> insert into t1 values (3,1,1);
INSERT 27521 1
tests=> select * from t1;
np | nt | na
----+----+----
3 | 1 | 1
(1 row)
tests=>
tests=> CREATE TABLE t2(
tests(> nq SERIAL UNIQUE NOT NULL,
tests(> np int NOT NULL,
tests(> nt int NOT NULL,
tests(> na int NOT NULL,
tests(> FOREIGN KEY (na,np,nt) REFERENCES t1 (na,np,nt)) WITH OIDS;
NOTICE: CREATE TABLE will create implicit sequence "t2_nq_seq" for serial column "t2.nq"
NOTICE: CREATE TABLE / UNIQUE will create implicit index "t2_nq_key" for table "t2"
CREATE TABLE
tests=>
tests=> INSERT INTO t2 VALUES (DEFAULT,3,1,1);
INSERT 27534 1
tests=> select * from t2;
nq | np | nt | na
----+----+----+----
1 | 3 | 1 | 1
(1 row) |
Partager