💙 Supporting healthcare non-profits: Metadataloop is free for 6–12 months. Contact Us to get started.
Free Online Tool

SQL to DBML Converter

Paste CREATE TABLE statements, get DBML markup ready for dbdiagram.io.

Open the Mermaid / DBML Converter →

Overview

DBML (Database Markup Language) is the format used by dbdiagram.io and other ER-diagram tools. Hand-writing DBML for an existing database is tedious — paste your CREATE TABLE statements and MetaDataLoop emits DBML with table blocks, column types, primary key markers, and Ref: lines for every foreign key relationship.

What you get

✓ INCLUDED
Reads PostgreSQL, MySQL, Snowflake, and SQL Server DDL
✓ INCLUDED
Emits DBML Table {} blocks with column types and notes
✓ INCLUDED
Detects PRIMARY KEY and emits [pk] inline
✓ INCLUDED
Foreign keys become Ref: orders.user_id > users.id lines
✓ INCLUDED
Paste output directly into dbdiagram.io for an interactive diagram

Example

Input
CREATE TABLE users (
    id INT PRIMARY KEY,
    email VARCHAR(255) NOT NULL
);

CREATE TABLE orders (
    id INT PRIMARY KEY,
    user_id INT NOT NULL,
    total DECIMAL(10,2),
    FOREIGN KEY (user_id) REFERENCES users(id)
);
Output
Table users {
  id    int          [pk]
  email varchar(255) [not null]
}

Table orders {
  id      int           [pk]
  user_id int           [not null]
  total   decimal(10,2)
}

Ref: orders.user_id > users.id

Frequently asked questions

Does dbdiagram.io accept this output?
Yes. Paste the DBML directly into the editor at dbdiagram.io — the diagram renders immediately.
Can I round-trip DBML back to SQL?
dbdiagram.io has its own export-to-SQL feature. Our tool is one-way: SQL → DBML.
What about composite primary keys?
Composite PKs are emitted as an indexes { (col1, col2) [pk] } block — DBML's standard for multi-column PKs.

Try it now

No signup, no install — runs entirely in your browser.

Open the Mermaid / DBML Converter →

⚠ Confirm Delete