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.
- Column types are emitted as-is (with parenthetical arguments stripped to the plain type where DBML convention prefers it). SQL
VARCHAR(255)becomes DBMLvarchar;INTstaysint. - Constraints —
PRIMARY KEYbecomes[pk];AUTO_INCREMENT/SERIALaddsincrement;NOT NULLbecomes[not null];UNIQUEbecomes[unique];DEFAULT xbecomes[default: x]. - Foreign keys from both inline
REFERENCESand table-levelFOREIGN KEYclauses are emitted asRef: table.col > referenced_table.colat 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.