Home › Developer Tools › SQL to ER Diagram

SQL to ER Diagram

Paste your CREATE TABLE statements and get an entity-relationship diagram instantly: primary keys, foreign keys, unique columns and crow's foot relationship lines. Drag tables into place, then download a PNG or SVG, or copy the diagram as Mermaid code. Your SQL never leaves your browser.

Last updated:

Display

Diagram

Drag tables to move them, drag the background to pan, Ctrl + scroll to zoom. Click a table to highlight its relationships.

exactly one zero or one zero or many nullable foreign key
Advertisement
Advertisement

How to use the SQL to ER Diagram

  1. Paste your SQL: one or more CREATE TABLE statements, or open a .sql dump file. Use the sample menu to see examples.
  2. Check the summary under the editor: it counts tables, columns and relationships and lists anything it could not resolve.
  3. Arrange the diagram: drag tables, drag the background to pan, and use Fit or Ctrl + scroll to zoom. Click a table to highlight its links.
  4. Adjust the display: hide data types, show only key columns or mark nullable columns.
  5. Download PNG or SVG for docs and slides, or copy the Mermaid code to paste into Markdown, GitHub or a wiki.

What an ER diagram shows

An entity-relationship diagram (ERD) draws each table as a box listing its columns, and connects tables wherever a foreign key in one table points to a key in another. It is the fastest way to understand an unfamiliar database, review a schema change or document a project. This tool builds a physical ERD: it shows the real table and column names and data types exactly as they appear in your DDL.

In your SQLIn the diagram
id INT PRIMARY KEY or PRIMARY KEY (a, b)PK badge, underlined column name
customer_id INT REFERENCES customers(id)FK badge and a line to customers
email VARCHAR(255) UNIQUEUQ badge
Foreign key column is NOT NULLSolid line, "exactly one" at the parent end
Foreign key column allows NULLDashed line, "zero or one" at the parent end
Foreign key column is also UNIQUE (or the whole PK)One-to-one: "zero or one" at the child end
Ordinary foreign keyOne-to-many: crow's foot at the child end
Table referencing itself (parent_id)A loop on the right side of the table

Getting the CREATE TABLE script from your database

DatabaseCommand (schema only, no data)
MySQL / MariaDBmysqldump --no-data -u user -p dbname > schema.sql
PostgreSQLpg_dump --schema-only dbname > schema.sql
SQLitesqlite3 app.db .schema > schema.sql
SQL ServerSSMS: right-click the database → Tasks → Generate Scripts (schema only)
Rails / Django / PrismaUse the generated structure.sql, sqlmigrate output or prisma migrate diff --script

Tips for a readable diagram

  • Declare your foreign keys. Links are drawn only from REFERENCES constraints, which is also what keeps your data consistent.
  • Use "Key columns only" for large schemas: the boxes shrink to the PK and FK columns, so the structure stands out.
  • Layout logic: tables that nothing depends on sit on the left; each table is placed one column to the right of the tables it references. Drag boxes to fine-tune, and press Re-arrange to start over.
  • Diagram a subset by pasting only the tables you care about; references to missing tables are listed as warnings rather than breaking the diagram.
  • Keep it in version control by copying the Mermaid code into a README; it re-renders whenever the schema changes.

Frequently asked questions

Which SQL dialects does the ER diagram generator support?

It reads the CREATE TABLE syntax shared by MySQL, MariaDB, PostgreSQL, SQLite and SQL Server, including backtick, double-quote and [bracket] identifiers, schema-qualified names, AUTO_INCREMENT, SERIAL, IDENTITY and table options like ENGINE=InnoDB. Statements other than CREATE TABLE and ALTER TABLE … ADD are ignored.

How are relationships detected?

From foreign keys: inline column REFERENCES clauses, FOREIGN KEY (…) REFERENCES table (…) constraints inside the table and ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY statements. If a foreign key does not name the referenced columns, the parent table's primary key is used. Column names alone are never guessed, so tables without declared foreign keys appear unconnected.

How do I read the crow's foot symbols?

The end at the referenced (parent) table shows exactly one (two bars) when the foreign key column is NOT NULL, or zero or one (bar and circle) when it is nullable. The end at the child table shows zero or many (crow's foot and circle), or zero or one when the foreign key column is unique or is the whole primary key, which makes it a one-to-one link.

Can I export the diagram?

Yes. Download PNG renders the diagram at double resolution on a white background, ideal for documents and slides. Download SVG gives a scalable vector file you can edit in Inkscape, Figma or Illustrator. Copy as Mermaid produces erDiagram code that GitHub, GitLab and many wikis render in Markdown.

Can I get a diagram from an existing database?

Export the schema as SQL first, then paste it here. For example: mysqldump --no-data dbname, pg_dump --schema-only dbname, sqlite3 file.db .schema, or Script Database as CREATE in SQL Server Management Studio. Only the table definitions are needed, not the data.

Is my database schema uploaded anywhere?

No. Parsing, layout and image export all run in JavaScript in your browser. The SQL you paste and your table positions are kept only in this browser's local storage so they are still there when you come back.

Why is a table shown without links even though it has an id column like user_id?

The diagram only draws relationships that are declared as foreign keys. Many schemas (and some engines like MyISAM) skip foreign key constraints. Add a REFERENCES clause or an ALTER TABLE … ADD FOREIGN KEY line to the pasted SQL and the link appears.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

Database Schema DesignerDesign tables and relationships visually, then export SQL for MySQL, PostgreSQL or SQLite.SQL Create Table GeneratorDefine columns, keys, defaults and indexes; get CREATE TABLE SQL for MySQL, Postgres and more.Mermaid Diagram EditorWrite Mermaid code and see flowcharts, sequence, Gantt and ER diagrams live. Export SVG or PNG.SQL Formatter & BeautifierFormat, beautify or minify SQL queries for MySQL, PostgreSQL and more.JSON to Excel ConverterTurn JSON into a styled .xlsx spreadsheet; nested arrays become their own linked sheets.JSON to CSVConvert JSON data to CSV for spreadsheets.CSV to JSONConvert CSV data to JSON with live preview.Excel to CSVConvert XLSX spreadsheets to CSV.CSV ViewerOpen a CSV or TSV file as a sortable, filterable table.Excel Viewer (XLSX / XLS)Open XLSX, XLS and ODS spreadsheets in your browser without Excel.Line Ending ConverterConvert text and files between CRLF, LF and CR line endings.Markdown to HTMLConvert Markdown to clean HTML with a live editor.XML to JSONConvert XML to JSON with validation.Text Encoding ConverterDetect and convert text file encodings like UTF-8, UTF-16 and Latin-1.JSON ViewerExplore JSON as a collapsible tree, search keys and values and copy any node's path.TTF to WOFF2 ConverterConvert TTF and OTF fonts to WOFF2 or WOFF and get a ready @font-face CSS snippet.Chmod CalculatorConvert Linux file permissions between checkboxes, octal (755) and symbolic (rwxr-xr-x) notation.JSON to TypeScriptGenerate TypeScript interfaces or types from JSON, with nested types and optional fields.Morse Code TranslatorTranslate text to Morse code and back, then play it as sound or a blinking light, or save a WAV.HTML Table GeneratorBuild HTML tables in an editable grid with styles, header rows, CSV import and live preview.Hex to Text ConverterConvert hex to text and text to hex with UTF-8 support and space, 0x, \x or comma formats.JSON to XML ConverterConvert JSON to well-formed XML with attributes, arrays and pretty print.JSON to YAML ConverterConvert JSON to clean YAML as you type, with indent, quoting and sort options.YAML to JSON ConverterConvert YAML to pretty or minified JSON, with errors pinned to the exact line.HTML to Markdown ConverterTurn HTML or pasted rich text into clean Markdown with tables and live preview.Markdown Table GeneratorBuild Markdown tables in a grid or paste from Excel/CSV, with alignment and preview.JSON ValidatorCheck JSON with the exact line and column of each error, fix tips and one-click auto-fix.Image to Base64Convert images to Base64 data URIs, CSS backgrounds and HTML img tags in your browser.Base64 to ImagePaste a Base64 string or data URI to preview, identify and download the image.JSON CompareCompare two JSON documents and see every added, removed and changed path.Hex to DecimalConvert hex to decimal instantly with steps and signed mode.Decimal to HexConvert decimal to hex instantly with steps and signed mode.Binary to DecimalConvert binary to decimal instantly with steps and signed mode.Decimal to BinaryConvert decimal to binary instantly with steps and signed mode.Two's Complement CalculatorDecimal to two's complement binary and back for 4-64 bits, with invert-and-add-1 steps.XML to CSV ConverterConvert XML to CSV: detects repeating records, flattens nested data, pick your columns.CSV to XML ConverterConvert CSV to well-formed XML with custom root and row names, escaping and pretty print.TOML to JSON ConverterConvert TOML to JSON and JSON to TOML with a full v1.0 parser and clear error lines.CSV to Markdown TableConvert CSV to a neatly aligned GitHub Markdown table with column alignment and live preview.CSV TransposeSwap rows and columns of CSV, TSV or pasted spreadsheet data, with delimiter auto-detect.Date Format ConverterConvert any date to ISO 8601, RFC 2822, Unix time and custom strftime, moment or Java patterns.ENV to JSON ConverterConvert .env files to JSON or YAML and JSON back to .env, with quotes and multiline values.File to Base64Convert any file to a Base64 string or data URI with MIME detection, line wrap and download.HTML Table to CSVExtract any table from HTML or page source to CSV, TSV or JSON, with colspan and rowspan handled.IEEE 754 Floating Point ConverterConvert decimals to 32/64-bit IEEE 754 floats: toggle bits, see hex, exact value and rounding error.INI to JSON ConverterConvert INI and CFG files to JSON and JSON back to INI, with sections, arrays and types.IP Address ConverterConvert IPv4 to decimal, hex, binary, octal and back, with class and private/public check.ISBN Converter & ValidatorConvert ISBN-10 to ISBN-13 and back, validate check digits and hyphenate, one or in bulk.JSON Flatten / UnflattenFlatten nested JSON to dot or bracket path keys, or unflatten flat keys back to nested JSON.JSON to Dart ClassTurn JSON into Dart model classes with fromJson, toJson, null safety and nested classes.JSON to Java ClassTurn JSON into Java POJOs or records with Lombok, getters/setters and Jackson or Gson annotations.JSON to Kotlin Data ClassTurn JSON into Kotlin data classes for kotlinx.serialization, Gson, Moshi or Jackson.JSON to Markdown TableTurn a JSON array of objects into a GitHub Markdown table with column picker and alignment.JSON to PHP ArrayConvert JSON to PHP array code (short [] or array()) and PHP arrays back to JSON.JSON to Rust StructTurn JSON into Rust structs with serde derives, rename attributes, Option and Vec types.JSON to SQL ConverterConvert a JSON array of objects to CREATE TABLE and INSERT statements for MySQL, Postgres, SQLite.JSON to Swift StructTurn JSON into Swift Codable structs with CodingKeys, optionals and nested types.JSON to TOML ConverterConvert JSON to clean TOML with tables, arrays of tables, inline tables and dates.JSONL to JSON ConverterConvert JSON Lines / NDJSON to a JSON array and back, with line-level error reports.Properties to YAML ConverterConvert Java .properties to nested YAML (application.yml) and YAML back to properties.PX to EM ConverterConvert pixels to em using the parent font size, and em back to px, with conversion tables.Query String to JSONConvert URL query strings to JSON with nested brackets and arrays, and JSON back to a query string.REM to PX ConverterConvert CSS rem values to pixels for any root font size, with a quick 0.25–6rem table.SQL to JSON ConverterConvert SQL INSERT statements and dumps into a JSON array of row objects, with CSV export.TSV to CSV ConverterConvert TSV to CSV and back, or between tab, comma, semicolon and pipe, with correct quoting.TypeScript to JavaScriptConvert TypeScript or TSX to clean JavaScript instantly: strip types, keep or compile JSX.XML to YAML ConverterConvert XML to clean YAML with attributes, text nodes, lists and exact error lines.YAML to XML ConverterConvert YAML to pretty, well-formed XML with custom root, attributes and array item tags.
See all 129 Data & File Format Converters →