Table 「test.group_info」「test.member_info」
testdb=# \d group_info
Table "test.group_info"
Column | Type | Collation | Nullable | Default
------------+-------------------+-----------+----------+---------
group_id | integer | | not null |
group_name | character varying | | |
Indexes:
"group_info_pkey" PRIMARY KEY, btree (group_id)
Referenced by:
TABLE "member_info" CONSTRAINT "member_info_group_id_fkey" FOREIGN KEY (group_id) REFERENCES group_info(group_id)
testdb=# \d member_info
Table "test.member_info"
Column | Type | Collation | Nullable | Default
----------+-------------------+-----------+----------+---------
id | integer | | not null |
name | character varying | | |
group_id | integer | | |
Indexes:
"member_info_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
"member_info_group_id_fkey" FOREIGN KEY (group_id) REFERENCES group_info(group_id)
testdb=# SELECT * FROM group_info;
group_id | group_name
----------+------------
1 | 営業部
2 | 技術部
3 | 総務部
(3 rows)
testdb=# SELECT * FROM member_info;
id | name | group_id
----+------+----------
1 | 河野 | 1
2 | 島田 | 3
(2 rows)
testdb=# INSERT INTO member_info VALUES (3, '木村', 1);
INSERT 0 1
testdb=# UPDATE group_info SET group_id = 4 WHERE group_id = 2;
UPDATE 1
testdb=# DELETE FROM member_info WHERE id = 1;
DELETE 1
testdb=# SELECT * FROM group_info;
group_id | group_name
----------+------------
1 | 営業部
3 | 総務部
4 | 技術部
(3 rows)
testdb=# SELECT * FROM member_info;
id | name | group_id
----+------+----------
2 | 島田 | 3
3 | 木村 | 1
(2 rows)
この記事が気に入ったらサポートをしてみませんか?