DBML to SQL & ERD Online

Convert DBML (dbdiagram.io syntax) to PostgreSQL, MySQL, SQL Server or SQLite DDL, SQL DDL back to DBML, and draw an ERD as SVG or PNG.

Free tool: 20 requests per minute.

Result

Press “Run” to see the result.

DBML is the readable schema language of dbdiagram.io. Send dbml and get CREATE statements for to=postgres (default), mysql, mssql or sqlite: tables with schemas, column types, primary keys (also composite), increment (IDENTITY / AUTO_INCREMENT / AUTOINCREMENT), unique, not null, defaults (strings, numbers, booleans, expressions), enums (CREATE TYPE in PostgreSQL, ENUM in MySQL, CHECK constraints elsewhere), indexes (composite, expression, unique, named, type: hash), notes as COMMENT ON / COMMENT / extended properties, and foreign keys from inline or block refs (>, <, -, composite, delete: cascade). Many-to-many refs (<>) create a junction table.

The reverse works too: send sql (CREATE TABLE, CREATE INDEX, CREATE TYPE … AS ENUM, ALTER TABLE ADD FOREIGN KEY / PRIMARY KEY, COMMENT ON, MySQL inline KEY / ENUM / COMMENT, SQL Server [brackets] and IDENTITY) and get DBML, the JSON model (to=json) or the DDL of another database, e.g. MySQL dump to PostgreSQL.

to=svg or to=png draws an entity-relationship diagram: tables placed in layers (referenced tables to the left of the tables that point to them), primary keys highlighted, foreign keys marked, crow's-foot ends for "many", header colours from headercolor, theme=dark. The parser is APIBox's own (no @dbml/core); TablePartial, records and DBML 3 sticky notes are not supported, and expression indexes are written as given for every database.

Use this in your code

curl -X POST "https://apibox.io.vn/v1/dbml" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"dbml":"Table users {\n  id int [pk, increment]\n  email varchar(255) [unique, not null]\n}\n\nTable posts {\n  id int [pk]\n  user_id int [ref: > users.id]\n  title varchar\n}","to":"postgres"}'

API documentation → Get a free API key

FAQ

Is it compatible with dbdiagram.io?

It follows the DBML syntax: Project, Table (alias, settings, indexes, notes), Ref (inline, short, long, composite, actions), Enum, TableGroup and Note. TablePartial and records are not supported yet.

How are relationships turned into foreign keys?

For a > b the foreign key goes on a (many side); for a < b on b; a - b puts it on a; a <> b creates a junction table a_b with two foreign keys.

Can I get a PNG?

Yes, to=png renders the diagram (scale up to 3). SVG stays sharp at any size and is better for documents.