DevTools Logo

DBML Playground

DBML Playground

Write DBML and see an ER diagram plus SQL DDL update live — entirely in your browser.

Runs in your browser
2 tables · 1 refs
Try an example

DBML source

15 lines

Diagram & DDL

postgres DDL
>usersid : int [PK]email : varchar(255) [U]name : textpostsid : int [PK]user_id : int [*]title : varchar(200)

Schema outline

  • users: id, email, name
  • posts: id, user_id, title

postgres DDL

Examples

Blog CMS

Input
Table authors { id int [pk] } + Table articles { author_id int } + Ref: articles.author_id > authors.id
Output
Two-tier diagram with one FK edge and two CREATE TABLE statements

Reference layering puts the parent table above the child, and the FK becomes an ALTER TABLE constraint for most dialects.

Dialect switch

Input
id int [pk, increment]
Output
SERIAL / AUTO_INCREMENT / AUTOINCREMENT / IDENTITY(1,1)

The same column emits engine-specific auto-increment syntax and identifier quoting.

Bad reference

Input
Ref: posts.user_id > ghost.id
Output
Line 4: Ref points to unknown table "ghost"

Invalid references are surfaced inline; the rest of the schema still renders.

About this tool

DBML Playground is a private scratchpad for dbdiagram.io's database markup language. Type Table, Ref and Enum blocks and an ER diagram updates live: tables become boxes with typed column rows and PK/U/* badges, relationships become labelled edges between them.

The same parsed model also generates SQL DDL for PostgreSQL, MySQL, SQLite and SQL Server. Dialects get their own identifier quoting and type mappings — serial versus AUTO_INCREMENT versus IDENTITY, JSONB versus JSON versus TEXT — so you can sketch once and export for the target engine.

Parsing, layout and export all happen in the browser with no accounts and no network calls. A textual schema outline mirrors the diagram for screen readers, and parse issues include line numbers so a bad Ref or unclosed block is quick to fix.

What this tool does not do

  • Supports a DBML subset; advanced dbdiagram features such as table groups and custom styles are not parsed.
  • DDL export covers core columns, primary/unique/not-null flags and foreign keys; indexes beyond unique constraints are not emitted.
  • The SVG renderer uses a simple layered layout and is intended for small to medium schemas, not hundreds of tables.

How to use this tool

  1. Write or load DBML

    Start from the e-commerce sample or paste your own Table and Ref blocks; the diagram and outline update as you type.

  2. Choose a dialect

    Switch Postgres, MySQL, SQLite or MSSQL to re-render CREATE TABLE and foreign-key statements with the right types and quoting.

  3. Inspect the diagram

    Tables are layered by reference direction; PK, unique and not-null columns carry text badges so colour is never the only signal.

  4. Copy or download

    Copy the generated DDL or download it as schema.sql. The diagram is available as portable inline SVG with no remote fonts.

Use cases

Schema sketching

Draft a schema in DBML before writing migrations, with an instantly readable diagram to review.

Cross-engine migration

Export the same model as Postgres, MySQL, SQLite or MSSQL DDL to compare type and constraint syntax.

Documentation diagrams

Copy the inline SVG into a README or docs page without an account or hosted service.

Supported DBML constructs

SyntaxMeaning
Table users { … }A table with typed column rows
id int [pk, increment]Primary key with engine-appropriate auto-increment
email varchar(255) [unique, not null]Unique, required column
state text [note: 'draft']Column note
Ref: posts.user_id > users.idOne-to-many relationship (also < and -)
Enum status { draft published }Enum values; emitted as a Postgres CREATE TYPE

Comments with // and /* … */ are ignored; unknown tokens are reported with line numbers.

Common mistakes

Mistake:Expecting full dbdiagram.io syntax.

Fix:This is a practical DBML subset: Table, Ref, Enum, Note and Project blocks with common column flags. Unsupported tokens are reported rather than silently dropped.

Mistake:Assuming many-to-many Refs are synthesized.

Fix:DBML models many-to-many with a junction table and two one-to-many Refs; the diagram draws both edges and does not invent an n-m marker.

Mistake:Pasting SQL DDL into the DBML editor.

Fix:DBML is its own language. Use an SQL-first diagram tool to start from DDL; here you write Table blocks and export SQL out.

Frequently asked questions

What is DBML syntax?

DBML (Database Markup Language) is dbdiagram.io's compact schema language. A Table block lists typed columns with optional flags: `id int [pk, increment]`, `email varchar(255) [unique, not null]`. Ref lines describe relationships such as `Ref: posts.user_id > users.id`, and Enum blocks list allowed values. This playground supports that practical subset and reports unknown tokens with line numbers.

Which SQL dialects does the export support?

PostgreSQL, MySQL, SQLite and SQL Server (MSSQL). Each gets its own identifier quoting — double quotes, backticks or brackets — and its own type and auto-increment mapping: SERIAL in Postgres, AUTO_INCREMENT in MySQL, AUTOINCREMENT in SQLite, IDENTITY(1,1) in MSSQL. Foreign keys are emitted as ALTER TABLE constraints everywhere except SQLite, where they belong inline in CREATE TABLE.

Can I import existing SQL into DBML here?

No — this tool goes one direction: DBML in, diagram and DDL out. An SQL-first diagram tool is the right choice when you already have CREATE TABLE statements. Your DBML source stays local and can be exported as SQL for the target engine.

How are relationships rendered?

Each Ref becomes a labelled edge between the two table boxes. Tables are layered by reference direction so parents sit above children, and the edge label shows the DBML cardinality marker (>, < or -). DBML has no synthetic many-to-many marker: a junction table with two one-to-many Refs is the standard representation and is drawn as two edges.

Is my schema private?

Yes. Parsing, layout and export all run inside your browser tab. There are no accounts, no network requests and no cloud projects. The generated SVG uses a system font stack with no remote references, so it can be pasted into documentation without phoning home.

References & standards