Diagram Desk

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

memberPK id intemail varchar(100)nickname varchar(30)boardPK id inttitle varchar(50)postPK id bigintFK board_id intFK writer_id inttitle varchar(200)created_at timestampreplyPK id bigintFK post_id bigintFK writer_id intcontent text
ER diagram · 18 shapes

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

ShapeSymbolConnections
memberEntityholds id, email, nickname · → post, reply
boardEntityholds id, title · → post
postEntityholds id, board_id, writer_id, title, created_at · → reply · ← board, member
replyEntityholds id, post_id, writer_id, content · ← post, member

Symbols used here

SymbolMeaning
EntityA 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 oneTwo short bars at the line end.
Zero or oneA bar and a circle.
Zero or manyA crow's foot and a circle.

All er diagram symbols and how to draw

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
);

More er diagram examples

All SeewolLabs tools