DBML Editor
Write DBML on the left, watch the ER diagram redraw on the right. Convert DBML to SQL for four databases, or turn an existing SQL schema into DBML.
DBML → SQL
CREATE TYPE order_status AS ENUM ('pending', 'paid', 'shipped', 'cancelled');
CREATE TABLE customers (
id SERIAL PRIMARY KEY,
email VARCHAR NOT NULL UNIQUE,
full_name VARCHAR,
created_at TIMESTAMP DEFAULT now()
);
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
customer_id INTEGER NOT NULL,
status ORDER_STATUS NOT NULL,
placed_at TIMESTAMP,
FOREIGN KEY (customer_id) REFERENCES customers (id)
);
CREATE TABLE products (
id SERIAL PRIMARY KEY,
sku VARCHAR NOT NULL UNIQUE,
name VARCHAR NOT NULL,
price_cents INTEGER NOT NULL
);
CREATE TABLE order_items (
order_id INTEGER,
product_id INTEGER,
quantity INTEGER NOT NULL DEFAULT 1,
PRIMARY KEY (order_id, product_id),
FOREIGN KEY (order_id) REFERENCES orders (id),
FOREIGN KEY (product_id) REFERENCES products (id)
);
SQL → DBML
Table authors {
id INT [pk, increment]
name VARCHAR(100) [not null]
}
Table books {
id INT [pk, increment]
author_id INT [not null]
title VARCHAR(200) [not null]
}
Ref: books.author_id > authors.id
DBML syntax reference
| Construct | Example | What it does |
|---|---|---|
| Table | Table users {
id integer [pk, increment]
email varchar [not null, unique]
} | Declares a table. Each line is column name, type, and optional settings in brackets. |
| Column settings | [pk] [increment] [not null] [null] [unique] [default: 0] [note: '…'] | Combine with commas. Defaults: numbers and quoted strings as-is, expressions in backticks, e.g. default: `now()`. |
| Inline ref | user_id integer [ref: > users.id] | Foreign key on the column itself. > many-to-one, < one-to-many, - one-to-one, <> many-to-many. |
| Ref block | Ref: posts.user_id > users.id Ref: a.(x, y) > b.(x, y) | Relationship declared outside the table; the second form is a composite key. |
| Indexes | Indexes {
(order_id, product_id) [pk]
email [unique]
} | Goes inside a Table. Composite primary keys are declared here. |
| Enum | Enum order_status {
pending
paid
} | A named set of values you can use as a column type. |
| Note | Note: 'Stores one row per signup' | Documentation for a table or column; shown by DBML tooling. |
Why teams write schemas in DBML
SQL DDL differs between databases and is noisy to read: engine options, constraint names, quoting rules. DBML strips that away so a schema fits on one screen and diffs cleanly in pull requests. It is popular for design reviews before a migration is written, and for documenting an existing database. When you are ready to build, convert the DBML to SQL for your database above, then review the output. Converters cannot know about your indexes for query patterns, check constraints or partitioning.
Prefer diagrams in Markdown? The Mermaid ER diagram generator turns the same schema into erDiagram code that GitHub renders natively.
Questions
What is DBML?
DBML (Database Markup Language) is an open-source, human-readable language for describing database schemas, created by Holistics for dbdiagram.io. It is designed for documentation and diagrams rather than for running against a database, so it stays short and database-agnostic.
Is this a dbdiagram.io alternative?
For quick jobs, yes: you can write DBML, see the diagram, convert to SQL and export SVG or PNG without an account. It does not offer cloud-saved projects or team sharing; your work is kept only in this browser.
How do I convert DBML to SQL?
Write or paste DBML in the editor, choose a target database under “DBML → SQL”, and copy the output. Tables are ordered so referenced tables are created first, foreign keys become FOREIGN KEY constraints, and many-to-many refs (<>) become junction tables.
How do I convert SQL to DBML?
Paste CREATE TABLE statements into the “SQL → DBML” box. Columns, primary keys, NOT NULL, UNIQUE, defaults, auto-increment and foreign keys are carried over.
Which DBML features are supported?
Table blocks with column settings (pk, increment, not null, unique, default, note, inline ref), Indexes blocks with composite primary keys, Enum blocks, Ref blocks and short Ref: lines with >, <, - and <>. TableGroup and Project blocks are accepted and ignored.
Related tools
- ER Diagram GeneratorPaste CREATE TABLE statements or DBML and get a draggable crow’s-foot diagram.
- Mermaid ER DiagramTurn a SQL schema into Mermaid erDiagram code for GitHub, GitLab and Notion.
- Crow’s Foot NotationER diagram symbols and a cardinality builder that reads relationships aloud.
- SQL Data TypesThe same type across MySQL, PostgreSQL, SQL Server, Oracle and SQLite.