N
NJHTools

Free Online DBML Editor

Write your schema in DBML, the open database markup language, and watch the ER diagram update as you type. It is a free DBML editor that runs entirely in your browser, with no signup, and exports SQL for PostgreSQL, MySQL, SQL Server or Oracle.

DBML codeYour schema stays in this browser.

Tab indents. Press Esc, then Tab, to move focus out. Autosaved in this browser.

How to draw a database diagram with DBML

  1. 1Start from the blog sample or a blank editor.
  2. 2Declare tables as Table name { column type [settings] }.
  3. 3Connect them with Ref lines such as Ref: posts.user_id > users.id.
  4. 4Drag tables into place; positions are autosaved with your DBML.
  5. 5Export SQL for your database, DBML, a Mermaid erDiagram, PNG or SVG.

DBML syntax basics

DBML (Database Markup Language) is an open, plain-text language for describing a schema. A table is a name and a block of columns, one per line, with settings in square brackets: Table users { id integer [pk, increment] email varchar(255) [not null, unique] created_at timestamp [default: `now()`] }.

Relationships are written as Ref: posts.user_id > users.id, where > means many-to-one, < means one-to-many, - means one-to-one and <> means many-to-many. You can also put the reference on the column itself: user_id integer [ref: > users.id]. Composite keys use parentheses, as in Ref: a.(x, y) > b.(x, y).

Enums are declared with enum post_status { draft published archived } and used as a column type. Add documentation with Note: 'text' inside a table or note: 'text' in a column's settings, and use // for comments that are not part of the schema.

Why design a schema in DBML

DBML is shorter than SQL and not tied to one database, so it is quick to sketch a model, discuss it in a pull request and keep it in your repository next to the code. Differences such as SERIAL versus AUTO_INCREMENT versus IDENTITY are handled when you export SQL for a specific database.

If you have used dbdiagram.io, DBML will look familiar: it is the open language that tool is built around, and plain DBML usually works in both. This editor is a separate, independent tool. It keeps everything in your browser and has no accounts, share links or team features.

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.

Frequently Asked Questions

Is this a dbdiagram.io alternative?↓

It is an independent, free DBML editor, not affiliated with dbdiagram.io. It uses the same open DBML language, so standard tables, refs, enums and notes usually carry over in either direction. It has no accounts, sharing or collaboration; diagrams stay in your browser.

What do >, <, - and <> mean in a DBML Ref?↓

They give the cardinality from the left column to the right one. > is many-to-one (many posts to one user), < is one-to-many, - is one-to-one and <> is many-to-many. In a real database a many-to-many relationship becomes a junction table when you export SQL.

Which export formats are available?↓

You can export CREATE TABLE SQL for PostgreSQL, MySQL, SQL Server or Oracle, the schema as DBML, a Mermaid erDiagram for Markdown docs on GitHub or GitLab, and the diagram itself as a PNG image or an SVG vector file. Convert SQL to DBML turns pasted SQL into DBML you can keep editing.

Is my database schema private? Is anything uploaded?↓

Nothing is uploaded. Parsing, layout and every export run in your browser, and the diagram is autosaved only in this browser's local storage. There are no share links on purpose, because table and column names can reveal how a product works. No signup is needed.

Is my diagram saved if I close the tab?↓

Yes. The source text and the positions of tables you dragged are autosaved in your browser's local storage, so they are still there next time on the same browser and device. Clearing site data removes them, so export DBML or SQL to keep a permanent copy.

All Text & Dev Tools →

Last updated: