SQL to Diagram
Paste your CREATE TABLE statements and instantly generate an interactive entity-relationship diagram. Auto-detects PostgreSQL, MySQL, SQLite, and SQL Server syntax.
Free SQL to Diagram Converter
Understanding a database schema from raw SQL is like reading a blueprint without the diagram. Our SQL to Diagram tool takes your CREATE TABLE statements and instantly generates an interactive visual representation — showing tables as nodes and foreign key relationships as connecting lines. It's the fastest way to understand or document an existing database.
How It Works
- Paste your SQL. Copy your CREATE TABLE statements from your database dump, migration files, or schema documentation and paste them into the input area.
- Select or auto-detect the dialect. The parser automatically detects whether your SQL is PostgreSQL, MySQL, SQLite, or SQL Server based on dialect-specific keywords and syntax patterns. You can also select the dialect manually.
- Click "Generate Diagram." The parser extracts tables, columns, data types, constraints (PRIMARY KEY, NOT NULL, UNIQUE, AUTO_INCREMENT), and foreign key relationships. The layout engine (ELK) arranges tables in a clean hierarchical layout.
- Explore and export. Pan and zoom the interactive diagram. Use the minimap for navigation in large schemas. Export as SQL, DSL text, or JSON.
What the Parser Handles
The SQL parser is designed to handle real-world DDL from production databases, not just textbook examples:
- Column definitions with data types, including parameterized types like VARCHAR(255) and DECIMAL(10,2).
- Inline constraints — PRIMARY KEY, NOT NULL, UNIQUE, DEFAULT, and REFERENCES on individual columns.
- Table-level constraints — composite PRIMARY KEYs, named FOREIGN KEY constraints, and UNIQUE constraints spanning multiple columns.
- Auto-increment — SERIAL/BIGSERIAL (PostgreSQL), AUTO_INCREMENT (MySQL), INTEGER PRIMARY KEY (SQLite), IDENTITY (SQL Server).
- Quoted identifiers — backticks (MySQL), double quotes (PostgreSQL/standard SQL), and brackets (SQL Server).
- Comments — both single-line (--) and block (/* */) comments are stripped before parsing.
- IF NOT EXISTS and other common clause variations.
Understanding the Diagram
Each table in the diagram displays its columns with visual indicators for constraints:
- PK (amber badge) — Primary key column. Highlighted in amber text.
- FK (blue badge) — Foreign key column. A connecting line shows the referenced table.
- NN — NOT NULL constraint.
- UQ — UNIQUE constraint.
Relationship lines connect foreign key columns to their referenced tables. Arrow direction indicates the dependency: the arrow points from the referencing table to the referenced table. This matches the direction of data flow — the table with the foreign key "depends on" the referenced table.
Common Use Cases
- Database documentation. Generate visual diagrams from your existing schema for documentation, onboarding materials, or architecture reviews.
- Legacy database analysis. Understand an unfamiliar database by pasting its DDL and seeing the structure at a glance.
- Migration planning. Visualize the current state of a schema before planning migrations or refactoring.
- Code review. Paste migration SQL from a pull request to quickly see what database changes are being proposed.
Need to Design from Scratch?
If you're creating a new database rather than visualizing an existing one, use our Visual Schema Designer. It provides a full design environment with table creation, column editing, relationship management, starter templates, and multi-dialect SQL export — all in an interactive drag-and-drop interface.