Diagram Desk

Employee and department ERD from SQL

Employee, department, project and assignment tables converted to an ERD. Table-level FOREIGN KEY constraints are read too, so the many-to-many through assignments shows up.

The diagram

deptPK dept_no intdept_name varchar(40)empPK emp_no intemp_name varchar(40)FK dept_no inthired_on dateprojectPK project_no intproject_title varchar(80)assignmentPK emp_no intPK project_no intjob varchar(30)
ER diagram · 15 shapes

Reading it step by step

  • 'dept' has 2 attributes, primary key dept_no.
  • 'emp' has 4 attributes, primary key emp_no, foreign key dept_no.
  • 'project' has 2 attributes, primary key project_no.
  • 'assignment' has 3 attributes, primary key emp_no, project_no.
  • Each 'dept' relates to zero or more 'emp'; each 'emp' to exactly one 'dept'.
  • Each 'emp' relates to zero or more 'assignment'; each 'assignment' to exactly one 'emp'.
  • Each 'project' relates to zero or more 'assignment'; each 'assignment' to exactly one 'project'.

Shape by shape

ShapeSymbolConnections
deptEntityholds dept_no, dept_name · → emp
empEntityholds emp_no, emp_name, dept_no, hired_on · → assignment · ← dept
projectEntityholds project_no, project_title · → assignment
assignmentEntityholds emp_no, project_no, job · ← emp, project

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 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 dept (
  dept_no INT PRIMARY KEY,
  dept_name VARCHAR(40) NOT NULL
);
CREATE TABLE emp (
  emp_no INT,
  emp_name VARCHAR(40) NOT NULL,
  dept_no INT NOT NULL,
  hired_on DATE,
  PRIMARY KEY (emp_no),
  FOREIGN KEY (dept_no) REFERENCES dept(dept_no)
);
CREATE TABLE project (
  project_no INT PRIMARY KEY,
  project_title VARCHAR(80)
);
CREATE TABLE assignment (
  emp_no INT NOT NULL,
  project_no INT NOT NULL,
  job VARCHAR(30),
  PRIMARY KEY (emp_no, project_no),
  FOREIGN KEY (emp_no) REFERENCES emp(emp_no),
  FOREIGN KEY (project_no) REFERENCES project(project_no)
);

More er diagram examples

All SeewolLabs tools