DBML to SQL Converter
Paste DBML — the schema-as-code language used by dbdiagram.io — and get runnable CREATE TABLE statements for PostgreSQL or MySQL, with primary keys, auto-increment columns, defaults, unique constraints, indexes and foreign keys derived from your Ref lines. Flip the direction to go from existing SQL DDL back to DBML so you can diagram or version-control a database you already have. Type names are mapped per dialect (jsonb ↔ json, timestamptz ↔ datetime, bytea ↔ blob, and so on), and everything is parsed in your browser — no schema is uploaded.
Do more than dbml to sql converter — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Choose a direction: DBML → SQL to generate DDL, or SQL → DBML to reverse-engineer existing CREATE TABLE statements.
- Paste your schema into the input box, then pick PostgreSQL or MySQL as the target dialect for DBML → SQL.
- Copy the generated output — paste DBML into dbdiagram.io to draw the ERD, or run the DDL against your database.
Frequently asked questions
What is DBML?
DBML (Database Markup Language) is an open, plain-text language for describing database schemas, created for dbdiagram.io. A schema is written as Table blocks containing columns with settings such as [pk], [not null] and [default:], plus Ref lines that declare relationships. Because it is just text, DBML fits into Git and code review in a way that a binary diagram file does not.
How do foreign keys in DBML map to SQL?
A Ref line describes the relationship and its direction. posts.user_id > users.id means many posts to one user, so the FOREIGN KEY is generated on posts. Writing users.id < posts.user_id expresses the same relationship from the other side and produces identical DDL. One-to-one relationships use a dash, and this converter emits a foreign key for those too.
Can I convert an existing database back into DBML?
Yes — switch the direction to SQL → DBML and paste your CREATE TABLE statements. Columns, types, primary keys, unique constraints, defaults, auto-increment and FOREIGN KEY clauses are converted into DBML Table blocks and Ref lines. To dump the DDL from a live database first, connect with Chat2DB (https://chat2db.ai/download or https://app.chat2db.ai) and export the schema, then paste it here.
