Free tool

Convert DBML to SQL

Paste DBML, pick a database, and get the CREATE TABLE script: tables, keys, indexes, enums, and foreign keys, written for PostgreSQL, MySQL, or SQL Server.

Free, no account. Your schema is converted on our server and not stored. Up to 200 KB.

What the script contains

  • A CREATE TABLE for every table, with its columns, defaults, and constraints.
  • Primary keys, unique constraints, and not-null constraints.
  • Every secondary index, as a CREATE INDEX after its table.
  • Foreign keys as ALTER TABLE ... ADD FOREIGN KEY after the tables, so two tables that reference each other can both be created.
  • Enums, in the form the chosen database has for them.

Types are written as you declared them

DBML does not have a type system of its own: uuid, jsonb, and nvarchar(200) are whatever the target database makes of them. So a schema written with PostgreSQL in mind and exported for MySQL still says uuid, which MySQL does not have.

The converter does not guess. It writes the type as declared and lists each one the chosen database will reject under the result, with the usual stand-in: CHAR(36) for uuid on MySQL and UNIQUEIDENTIFIER on SQL Server, DATETIMEOFFSET for timestamptz on SQL Server, INT AUTO_INCREMENT for serial on MySQL. Change the DBML and run it again. A PostgreSQL export that uses citext gets the CREATE EXTENSION line it needs prepended, so the script loads into an empty database.

From a one-off script to a schema you maintain

A generated script is right for a new database. For a database that already exists, what you need is the difference: the SQL migration generator compares two versions of a schema and writes the ALTER TABLE statements between them. Starting from SQL instead? Convert SQL to DBML first, or read how DBML and SQL differ.

DBML to SQL questions

Which databases can DBML be exported to here?

PostgreSQL, MySQL, and SQL Server. Choose one beside the Generate button and the CREATE TABLE statements are written with that database’s quoting, enum handling, and constraint syntax.

Does it translate column types between databases?

No, and on purpose. A type is written as you declared it, and any type the chosen database does not have is listed under the result with the usual replacement. Picking the replacement is a design decision, so the script is not changed behind your back.

How are DBML enums exported?

For PostgreSQL as a CREATE TYPE ... AS ENUM, for MySQL as an inline ENUM column type, and for SQL Server, which has no enum type, as a column with a CHECK constraint listing the allowed values.

Can I paste more than one DBML file?

Paste them one after another in the same box. Tables and enums resolve across the whole text, so a reference into a table defined further down works.

Put your schema on the board

Start on the free plan, no card needed. Pro is $5 a month when you outgrow it.

Start designing free