How to make a database diagram online
- 1Choose DBML or a SQL dialect (PostgreSQL, MySQL or SQL Server), or load the blog, e-commerce, SaaS or social sample.
- 2Type DBML or paste your CREATE TABLE statements; the diagram redraws as you edit.
- 3Drag tables into place, pan and zoom, or re-run auto-layout to tidy the diagram.
- 4Check primary keys, foreign keys, NOT NULL columns and enums on each table.
- 5Export SQL for PostgreSQL, MySQL, SQL Server or Oracle, DBML, Mermaid, PNG or SVG.
Crow's foot notation explained
Each relationship line connects a foreign key column to the key it points at. The end of the line shows how many rows can sit on that side: a single bar means one, and the three-pronged crow's foot means many. A line from posts.user_id to users.id with the crow's foot at posts reads as "one user has many posts, each post belongs to one user".
In full crow's foot notation a circle next to the end means zero is allowed (optional) and a second bar means at least one is required (mandatory). In SQL terms, a nullable foreign key column is the optional case and a NOT NULL foreign key is the mandatory one, so check the NOT NULL markers on the column when you need to know whether a row can exist without its parent.
One-to-one relationships have a bar at both ends and usually come from a foreign key that is also UNIQUE or the primary key. Many-to-many relationships cannot be stored directly in a relational database; they need a junction table, such as post_tags with post_id and tag_id, which turns them into two one-to-many lines.
Normalization tips that show up in a diagram
First normal form means one value per column: no comma-separated tag lists and no phone1, phone2, phone3 columns. If you see repeating columns, move them to a child table with a foreign key back to the parent. In the diagram that becomes a clear one-to-many line instead of a wide table.
Second and third normal form mean every non-key column depends on the key, the whole key and nothing but the key. A customer_email column on orders depends on the customer, not the order, so it belongs on customers. Tables with no relationship lines at all, or one table that every line points at, are both worth a second look.
Denormalize on purpose, not by accident. Copying a price onto order_items at the time of purchase is correct, because the order must not change when the catalog price does. Note such decisions in the schema so the next reader knows the duplication is intended.
Naming conventions for tables and keys
Pick one style and keep it: lowercase snake_case works in every database without quoting, because PostgreSQL folds unquoted names to lowercase and MySQL table names can be case-sensitive on Linux. Decide once whether table names are plural (users) or singular (user).
Name foreign keys after the table they point at plus _id, such as user_id or order_id, so relationships are obvious even without the diagram. Avoid reserved words like user, order and group as table names; they work only when quoted, which is easy to forget in queries.
Use consistent suffixes for common columns: created_at and updated_at for timestamps, is_ or has_ prefixes for booleans, and the same type for a key and every foreign key that references it, for example bigint on both sides.