SQL to DBML Converter

Paste CREATE TABLE SQL and get back a DBML schema ready to paste into dbdiagram.io. Each table becomes a DBML Table block with typed columns and attributes ([pk], [not null], [unique], [default: x]), and each foreign key becomes a standalone Ref: declaration so the visual diagram shows the relationships.

How to use the SQL to DBML Converter

Paste one or more CREATE TABLE statements — MySQL or PostgreSQL syntax — and click Generate DBML. The output is a DBML file you can paste directly into dbdiagram.io to get an interactive ER diagram.

  1. Column types are emitted as-is (with parenthetical arguments stripped to the plain type where DBML convention prefers it). SQL VARCHAR(255) becomes DBML varchar; INT stays int.
  2. ConstraintsPRIMARY KEY becomes [pk]; AUTO_INCREMENT/SERIAL adds increment; NOT NULL becomes [not null]; UNIQUE becomes [unique]; DEFAULT x becomes [default: x].
  3. Foreign keys from both inline REFERENCES and table-level FOREIGN KEY clauses are emitted as Ref: table.col > referenced_table.col at the end of the DBML output, which dbdiagram.io renders as relationship lines.

What is DBML and why convert SQL to it?

DBML (Database Markup Language) is a lightweight, human-readable DSL for describing relational database schemas. A DBML file consists of Table blocks containing column definitions, optional Indexes sub-blocks, and Ref declarations that describe foreign key relationships. The dbdiagram.io service renders DBML into interactive, shareable ER diagrams that teams use during design reviews, onboarding, and API documentation.

The typical workflow for a new project is design-first: write DBML, generate the visual diagram, review with stakeholders, then export DDL. But many teams operate with a legacy database that was never formally documented. For these teams, the reverse direction — SQL DDL to DBML — is what matters: they want to generate a diagram for an existing schema without rewriting it in DBML by hand. This converter does that mechanical reversal, parsing your DDL and emitting syntactically valid DBML that dbdiagram.io can render immediately.

DBML is also useful as a more readable schema format for version control. Keeping a schema.dbml file in the repository is more approachable to non-DBA contributors than raw SQL migration files, and any developer can open the dbdiagram.io URL to understand the data model without running the database locally.

Common use cases

  • Legacy database documentation — generate a dbdiagram.io-compatible DBML file from an old schema that was never diagrammed.
  • Team onboarding — paste the DBML into dbdiagram.io to share a live, interactive schema diagram with new developers via a URL.
  • Schema reviews — convert the proposed DDL to DBML and share the diagram link in a pull request for visual review.
  • Cross-team communication — product managers and designers who do not read raw SQL can understand the schema from a DBML diagram.
  • Documentation generation — use DBML as the source for auto-generated API docs or data dictionaries that reference table and column definitions.

Frequently asked questions

Does the output work directly in dbdiagram.io?

Yes — paste the DBML into the editor at dbdiagram.io and it renders the ER diagram immediately. If you have circular references or complex composite keys the diagram may show warnings; resolve these by adjusting the Ref lines manually.

How are composite primary keys handled?

Table-level PRIMARY KEY(a, b) is emitted with [pk] on each component column. dbdiagram.io marks both as primary key columns. The visual diagram treats the combination as the identifier.

Are CHECK constraints and triggers emitted?

No — DBML does not have syntax for CHECK constraints or triggers. These are SQL-only constructs. The converter skips them silently; add a Note field in the DBML manually if you want to document them.

What is the difference between Ref: a.col > b.col and a.col < b.col in DBML?

> means a.col is a foreign key referencing b.col (many-to-one from a to b). < is the reverse. - denotes a one-to-one. The converter always uses > (the FK column is on the left) which is the most common convention.

Can I round-trip between DBML and SQL?

Yes — this tool converts SQL to DBML, and the companion DBML to SQL Converter does the reverse. Some information is lost in each direction (SQL-only features like triggers, DBML-only features like table colors), but the structural schema round-trips cleanly.