Chalkline / Guides / SQL to ER diagram

Turn SQL into an ER diagram, and back

Your CREATE TABLE statements already describe your database. Here is how to read crow's foot notation, and how to turn SQL into a clear diagram in a few seconds.

Updated 7 November 2026 · 2 minute read

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 symbolMeans
A single barExactly one
A circle and a barZero or one
A crow's foot (three prongs) and a barOne or many
A circle and a crow's footZero 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:

The shop database drawn from its SQLThe shop database drawn from its SQLcustomersid int PKemail string UKname textordersid int PKcustomer_id int FKplaced_at timestampproductsid int PKtitle textprice floatorder_itemsorder_id int FKproduct_id int FKquantity intcustomer_idorder_idproduct_id
The shop database drawn from its SQLOpen this example in Chalkline →

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

  1. Open Chalkline and choose Diagram as text → Database (SQL), or simply paste your SQL onto the board.
  2. Press Apply. Tables and lines appear, laid out for you.
  3. Drag tables where you like. When you change the SQL and apply again, the tables you placed stay put.
  4. Use Copy SQL to turn your edited diagram back into CREATE TABLE statements.
Try it with the example databaseEdit the SQL and watch the tables follow
Open the example

What it understands

  • PostgreSQL, MySQL, SQLite and SQL Server quoting ("name", ` name , [name]`)
  • Inline REFERENCES, table level FOREIGN KEY (...) REFERENCES ..., and ALTER TABLE ... ADD FOREIGN KEY
  • PRIMARY KEY on 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_at if 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.