What an ER diagram shows
An entity relationship (ER) diagram shows the tables in a database, their columns, and how they link. Each table is a box. Each link is a line between two tables, with symbols at the ends that say how many rows on one side match rows on the other.
Crow's foot notation in one table
| End symbol | Means |
|---|---|
| A single bar | Exactly one |
| A circle and a bar | Zero or one |
| A crow's foot (three prongs) and a bar | One or many |
| A circle and a crow's foot | Zero or many |
So a line from customers to orders with a single bar at the customer end and a circle with a crow's foot at the order end reads: each order belongs to exactly one customer, and each customer has zero or many orders.
From SQL to a diagram
Here is a small shop database:
CREATE TABLE customers (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
name TEXT
);
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
customer_id INTEGER NOT NULL REFERENCES customers(id),
placed_at TIMESTAMP
);
CREATE TABLE products (
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
price NUMERIC
);
CREATE TABLE order_items (
order_id INTEGER REFERENCES orders(id),
product_id INTEGER REFERENCES products(id),
quantity INTEGER,
PRIMARY KEY (order_id, product_id)
);
And the diagram Chalkline draws from it:
Primary keys are marked PK, foreign keys FK and unique columns UK. A foreign key becomes a many to one line. A foreign key that is also unique becomes one to one. A nullable foreign key gets the optional circle.
How to do it
- Open Chalkline and choose Diagram as text → Database (SQL), or simply paste your SQL onto the board.
- Press Apply. Tables and lines appear, laid out for you.
- Drag tables where you like. When you change the SQL and apply again, the tables you placed stay put.
- Use Copy SQL to turn your edited diagram back into CREATE TABLE statements.
What it understands
- PostgreSQL, MySQL, SQLite and SQL Server quoting (
"name", `name,[name]`) - Inline
REFERENCES, table levelFOREIGN KEY (...) REFERENCES ..., andALTER TABLE ... ADD FOREIGN KEY PRIMARY KEYon a column or across several columns,UNIQUE,NOT NULL- Comments in
--and/* */are ignored
Tips for readable database diagrams
- Put the central table (often users or orders) in the middle and link tables around it.
- Hide audit columns such as
created_atif they add noise to the picture. - Use line jumps when lines cross, so readers can follow each relationship.
- Export to SVG or PDF for documentation, or to PowerPoint for a design review.
Want the diagram first and the SQL later? Draw tables by hand, connect them, and use Copy SQL. For the other UML diagrams, see UML class diagram examples.