SQL β DBML Converter | ERD Generator Docs
The SQL β DBML Converter lets you import existing SQL schema scripts and instantly transform them into DBML (Database Markup Language).
This enables fast ERD generation, visual exploration, and further customization β without manually rewriting schemas.
Whether youβre migrating a legacy database or reviewing a production schema, this tool provides a clean, readable DBML output ready for diagrams.
π Why Convert SQL to DBML?
SQL schemas are powerful but often:
- Dialect-specific
- Verbose
- Hard to visualize
DBML offers a database-agnostic, human-readable format that works seamlessly with ERD Generator.
Key benefits:
- Instant ERD visualization
- Cleaner schema documentation
- Easier collaboration across teams
- One source of truth for diagrams and exports
π§ Supported Source Types
The converter supports multiple input formats and SQL dialects:
type SourceType =
| "dbml"
| "mysql"
| "postgres"
| "json"
| "mssql"
| "postgresLegacy"
| "mssqlLegacy";Supported SQL Dialects
| Source Type | Use Case |
|---|---|
| mysql | MySQL / MariaDB schemas |
| postgres | Modern PostgreSQL schemas |
| mssql | SQL Server schemas |
| postgresLegacy | Older PostgreSQL DDL |
| mssqlLegacy | Legacy SQL Server scripts |
| json | Structured schema definitions |
| dbml | Re-import or refine existing DBML |
π οΈ How the SQL β DBML Conversion Works
Step 1: Paste or Import SQL
- Paste your
CREATE TABLE,ALTER TABLE, and constraint definitions - Or import schema files directly
Step 2: Select Source Type
Choose the correct SQL dialect to ensure accurate parsing and constraints mapping.
Step 3: Automatic Conversion
The engine:
- Extracts tables and columns
- Maps primary & foreign keys
- Converts indexes and constraints
- Normalizes output into valid DBML
Step 4: Live Diagram Preview
The generated DBML renders instantly in the diagram canvas for validation and refinement.
π§± Example Conversion
Input (PostgreSQL)
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT now()
);Output (DBML)
Table users {
id int [pk, increment]
email varchar(255) [unique, not null]
created_at timestamp [default: now()]
}The output is clean, readable, and ready for ERD visualization.
β οΈ Best Practices for Accurate Conversion
1. Use Complete Schemas
- Include all
CREATE TABLEstatements - Ensure foreign keys are defined explicitly
2. Avoid Mixed Dialects
- Donβt mix MySQL and PostgreSQL syntax in the same input
- Select the correct
SourceTypebefore conversion
3. Prefer Explicit Constraints
- Named constraints improve relationship detection
- Inline foreign keys convert more reliably
π§© Common Conversion Limitations
Some SQL features may not map 1 to DBML:
- Database-specific functions
- Triggers and stored procedures
- Advanced index types
- Vendor-specific column attributes
These are safely ignored or converted into notes when possible.
π οΈ Troubleshooting Conversion Errors
β Syntax Error
Cause: Unsupported or malformed SQL
Fix: Validate SQL or switch to legacy source type
β Missing Relationships
Cause: Foreign keys defined outside table scope
Fix: Ensure FK constraints are present in schema input
β Duplicate References
Cause: Multiple identical foreign keys
Fix: Remove duplicate ALTER TABLE references before conversion
π After Conversion: What You Can Do Next
Once converted to DBML, you can:
- Edit schemas in the DBML editor
- Apply layouts (Left β Right, Force-Directed)
- Customize table themes and backgrounds
- Filter visible tables via sidebar
- Drag and arrange tables freely
- Export diagrams as PNG / JPG
- Convert DBML back to SQL using DBML β SQL
β¨οΈ Productivity Tips
- Ctrl / Cmd + S β Save schema
- Ctrl / Cmd + B β Format DBML
- Ctrl / Cmd + Q β Command palette
- Use multiple tabs for side-by-side schemas
- Organize work using folders & workspaces
π Summary
The SQL β DBML Converter bridges the gap between existing databases and modern visual modeling.
It allows you to move faster, document better, and reason about your schema visually β without rewriting everything from scratch.
Use it as the starting point for every ERD.