Message board ERD from SQL
Drawn straight from CREATE TABLE statements: foreign keys (REFERENCES) become relationship lines, NOT NULL makes the parent side exactly one, otherwise zero or one.
The diagram
Reading it step by step
- 'member' has 3 attributes, primary key id.
- 'board' has 2 attributes, primary key id.
- 'post' has 5 attributes, primary key id, foreign key board_id, writer_id.
- 'reply' has 4 attributes, primary key id, foreign key post_id, writer_id.
- Each 'board' relates to zero or more 'post'; each 'post' to exactly one 'board'.
- Each 'member' relates to zero or more 'post'; each 'post' to exactly one 'member'.
- Each 'post' relates to zero or more 'reply'; each 'reply' to exactly one 'post'.
- Each 'member' relates to zero or more 'reply'; each 'reply' to zero or one 'member'.
Shape by shape
| Shape | Symbol | Connections |
|---|---|---|
| member | Entity | holds id, email, nickname · → post, reply |
| board | Entity | holds id, title · → post |
| post | Entity | holds id, board_id, writer_id, title, created_at · → reply · ← board, member |
| reply | Entity | holds id, post_id, writer_id, content · ← post, member |
Symbols used here
| Symbol | Meaning |
|---|---|
| Entity | A thing to store: name on top, attributes below. |
| Primary key (PK) | The attribute that identifies one row; underlined. |
| Foreign key (FK) | An attribute pointing to another entity's key. |
| Exactly one | Two short bars at the line end. |
| Zero or one | A bar and a circle. |
| Zero or many | A crow's foot and a circle. |
Diagram text
Paste this text into the editor to get the same picture, then change the names to fit your own work.
CREATE TABLE member (
id INT PRIMARY KEY,
email VARCHAR(100) UNIQUE NOT NULL,
nickname VARCHAR(30)
);
CREATE TABLE board (
id INT PRIMARY KEY,
title VARCHAR(50) NOT NULL
);
CREATE TABLE post (
id BIGINT PRIMARY KEY,
board_id INT NOT NULL REFERENCES board(id),
writer_id INT NOT NULL REFERENCES member(id),
title VARCHAR(200),
created_at TIMESTAMP
);
CREATE TABLE reply (
id BIGINT PRIMARY KEY,
post_id BIGINT NOT NULL REFERENCES post(id),
writer_id INT REFERENCES member(id),
content TEXT
);