SQL to ERD Generator — Visualize Any Database Schema
Import SQL turns CREATE TABLE statements into an entity-relationship diagram. Open the ERD Generator, click Import SQL, choose the dialect that matches your DDL, and paste the statements or pick a .sql file. Apply Schema converts them to DBML, replaces the editor content with that DBML, and draws the tables and relationships on the canvas.
The conversion runs in your browser. The converter files in this app do not make a network request, so the SQL you paste stays in the page.
How this tool handles it
The source dropdown has eight options, and PostgreSQL is selected by default:
- MySQL, PostgreSQL, Microsoft SQL Server go through the
@dbml/coreimporter, which uses a separate grammar for each dialect. - PostgreSQL (Legacy), MSSQL (Legacy) use the older importers in
@dbml/core. Try them only when the current option fails on a file. - SQLite uses a converter in this app (
sqliteToDbml), not@dbml/core. It reads text only, and it is covered on the SQLite page. - DBML is read as DBML and written back out as DBML.
- JSON is read as a
@dbml/coremodel object, not as SQL.
The output keeps the column types as written in the source. AUTO_INCREMENT, bigserial and GENERATED ... AS IDENTITY become increment. NOT NULL, UNIQUE and DEFAULT become settings. Foreign keys become Ref lines, with delete: and update: when the DDL states them. Enum types become Enum blocks. Multi-column keys and unique constraints go into an indexes block.
Worked example: SQL Server
Paste this with the Microsoft SQL Server option:
CREATE TABLE [dbo].[customers] (
[id] INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
[email] NVARCHAR(255) NOT NULL UNIQUE,
[plan] VARCHAR(10) NOT NULL DEFAULT 'free'
);
CREATE TABLE [dbo].[orders] (
[id] INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
[customer_id] INT NOT NULL CONSTRAINT [FK_orders_customers] FOREIGN KEY REFERENCES [dbo].[customers]([id]) ON DELETE CASCADE,
[total] DECIMAL(10,2) NOT NULL
);The DBML that comes out:
Table "dbo"."customers" {
"id" "INT IDENTITY(1,1)" [pk, not null]
"email" NVARCHAR(255) [unique, not null]
"plan" VARCHAR(10) [not null, default: 'free']
}
Table "dbo"."orders" {
"id" "INT IDENTITY(1,1)" [pk, not null]
"customer_id" INT [not null]
"total" DECIMAL(10,2) [not null]
}
Ref:"dbo"."customers"."id" < "dbo"."orders"."customer_id" [delete: cascade]The IDENTITY(1,1) seed stays inside the type name, and the id columns do not get the increment flag.
Gotchas
1. Choosing the wrong dialect. A MySQL file with backtick identifiers, pasted under PostgreSQL, fails. The importer throws with 8 diagnostics, and the dialog lists the lines that failed. Switch the dropdown to MySQL and apply again.
2. PostgreSQL pasted under SQLite is accepted. The SQLite converter raises no error for PostgreSQL DDL. The output keeps the public. prefix and the PostgreSQL types:
Table "public.customers" {
id bigserial [pk]
email varchar(255) [not null, unique]
created_at timestamptz [not null, default: `now()`]
plan text [not null, default: 'free'] // CHECK: plan IN ('free', 'pro')
}Choose PostgreSQL for PostgreSQL DDL.
3. CHECK constraints make the DBML invalid. A PostgreSQL column CHECK (plan IN ('free', 'pro')) becomes a check: setting in the column brackets, and the DBML parser rejects that setting on line 5 of the output. A MySQL CONSTRAINT ... CHECK becomes a Checks block, which the parser also rejects. Remove the CHECK clauses before you import. The diagram does not enforce them either way.
4. Other statements are left out. A CREATE VIEW in the PostgreSQL and SQLite tests did not appear in the output, and neither did a SQLite trigger. Keep those statements out of the paste.
5. SQL Server identity columns. The seed in IDENTITY(1,1) is copied into the type name, as shown above, and the column is not marked increment. Replace the type with INT in the SQL if you need the column to show as auto-increment.
Frequently asked questions
Which SQL dialects can I import?
Import SQL offers eight source options: DBML, MySQL, PostgreSQL, Microsoft SQL Server, JSON, SQLite, PostgreSQL (Legacy) and MSSQL (Legacy). PostgreSQL is selected by default. Pick the option that matches your DDL, because each option uses a different parser.
Does my schema leave the browser?
No. The converter files in this app do not make a network request, so the SQL is converted in the page and the result goes into the editor.
What does the import leave out?
In the statements tested for this page, views and triggers are not imported. A PostgreSQL partial index loses its WHERE clause. MySQL drops UNSIGNED, COLLATE and the ENGINE clause. SQLite drops generated-column expressions and standalone CREATE INDEX statements. CHECK constraints are not enforced in the diagram, and in PostgreSQL and MySQL they make the generated DBML invalid.
Why did the diagram change before the import reported an error?
Apply Schema puts the converted DBML into the editor first and checks it afterwards. If the DBML does not parse, the dialog shows the error, but the editor already holds the new text. Fix the SQL or the dialect and apply again.