読者です 読者をやめる 読者になる 読者になる

bate's blog

調べたこと実装したことなどを取りとめもなく書きます。

postgresql

linux

REFERENCES の使い方が分からず四苦八苦。


CREATE TABLE thread_tbl (
group_id SERIAL PRIMARY KEY,
thread_name TEXT,
date_time TIMESTAMP,
ip TEXT );

CREATE TABLE message_tbl (
id SERIAL PRIMARY KEY,
name TEXT,
message TEXT,
date_time TIMESTAMP,
thread_group INT REFERENCES thread_tbl (group_id),
ip TEXT );


bbs_db=# BEGIN;
BEGIN
bbs_db=# \i /usr/local/apache2/htdocs/bbs/create_table.sql
psql:/usr/local/apache2/htdocs/bbs/create_table.sql:5: NOTICE: CREATE TABLE will create implicit sequence "thread_tbl_group_id_seq" for serial column "thread_tbl.group_id"
psql:/usr/local/apache2/htdocs/bbs/create_table.sql:5: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "thread_tbl_pkey" for table "thread_tbl"
CREATE TABLE
psql:/usr/local/apache2/htdocs/bbs/create_table.sql:13: NOTICE: CREATE TABLE will create implicit sequence "message_tbl_id_seq" for serial column "message_tbl.id"
psql:/usr/local/apache2/htdocs/bbs/create_table.sql:13: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "message_tbl_pkey" for table "message_tbl"
CREATE TABLE
bbs_db=# \d
List of relations
Schema | Name | Type | Owner

                                                                                                              • -

public | message_tbl | table | postgres
public | message_tbl_id_seq | sequence | postgres
public | thread_tbl | table | postgres
public | thread_tbl_group_id_seq | sequence | postgres
(4 rows)

bbs_db=# COMMIT;
COMMIT

広告を非表示にする