Skip to content

Instantly share code, notes, and snippets.

@d-ikeda
Created March 2, 2015 09:23
Show Gist options
  • Save d-ikeda/7c8ddd3117507d7145e8 to your computer and use it in GitHub Desktop.
Save d-ikeda/7c8ddd3117507d7145e8 to your computer and use it in GitHub Desktop.
●リスト9.25 score列にNOT NULL制約を付けたテーブル定義
ch9_transaction=# CREATE TABLE ScoreRowsNN
ch9_transaction-# (student_id CHAR(4) NOT NULL,
ch9_transaction(# subject VARCHAR(8) NOT NULL,
ch9_transaction(# score INTEGER NOT NULL,
ch9_transaction(# CONSTRAINT pk_ScoreRowsNN PRIMARY KEY(student_id, subject));
CREATE TABLE
ch9_transaction=#
ch9_transaction=# INSERT INTO ScoreRowsNN VALUES ('A001', '英語', 0);
INSERT 0 1
ch9_transaction=# INSERT INTO ScoreRowsNN VALUES ('A001', '国語', 0);
INSERT 0 1
ch9_transaction=# INSERT INTO ScoreRowsNN VALUES ('A001', '数学', 0);
INSERT 0 1
ch9_transaction=# INSERT INTO ScoreRowsNN VALUES ('B002', '英語', 0);
INSERT 0 1
ch9_transaction=# INSERT INTO ScoreRowsNN VALUES ('B002', '国語', 0);
INSERT 0 1
ch9_transaction=# INSERT INTO ScoreRowsNN VALUES ('C003', '英語', 0);
INSERT 0 1
ch9_transaction=# INSERT INTO ScoreRowsNN VALUES ('C003', '国語', 0);
INSERT 0 1
ch9_transaction=# INSERT INTO ScoreRowsNN VALUES ('C003', '社会', 0);
INSERT 0 1
ch9_transaction=# select * from ScoreRowsNN;
student_id | subject | score
------------+---------+-------
A001 | 英語 | 0
A001 | 国語 | 0
A001 | 数学 | 0
B002 | 英語 | 0
B002 | 国語 | 0
C003 | 英語 | 0
C003 | 国語 | 0
C003 | 社会 | 0
(8 行)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment