Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

SQL to ER Diagram

Paste a schema; see its tables, keys and relationships, and export the diagram.

Developer No upload Works offline Free, no sign-up

CREATE TABLE, ALTER TABLE and CREATE INDEX statements from MySQL, MariaDB, PostgreSQL, SQLite or SQL Server — as written or as a schema dump. You can also drop a .sql file here. Other statements are skipped.

Diagram

Tab moves through the tables. Arrow keys move the selected table (with Shift, further) and Escape returns to the diagram, where arrow keys pan. Plus and minus zoom; 0 fits the diagram. A text list of the relationships is under the diagram.

exactly one zero or one zero or more identifying non-identifying PK primary key FK foreign key UK unique

Export as text

A Mermaid erDiagram for GitHub and GitLab Markdown, Notion, Obsidian or mermaid.live. Types Mermaid cannot write as one word, such as decimal(10,2), are shortened and kept in full in the attribute’s comment.

Next steps

About the SQL to ER Diagram

Paste the CREATE TABLE statements of a database — written by hand or dumped with mysqldump --no-data, pg_dump --schema-only, SQLite’s .schema or SQL Server Management Studio — and see it as an entity-relationship diagram: every table with its columns and types, primary keys (PK), foreign keys (FK) and unique columns (UK), and a line for every foreign key, drawn in crow’s foot notation.

The cardinality of each line comes from the keys themselves. A foreign key whose columns are all NOT NULL means each row has exactly one parent; a nullable one, zero or one. A foreign key that is also unique (its own primary key, or a unique constraint) makes the relationship one-to-one; otherwise a parent can have any number of children. A solid line means the foreign key is part of the child’s primary key (an identifying relationship); a dashed line means it is not.

Drag tables to arrange them, then download the diagram as SVG or PNG, or copy it as a Mermaid erDiagram (for GitHub and GitLab Markdown, Notion or Obsidian) or as DBML (for dbdiagram.io). The SQL is read in your browser and never uploaded.

How to use it

  1. Paste your SQL into SQL, drop or open a .sql file, or load one of the Examples. The dialect is detected from its syntax (backticks, ENGINE=, GO, IDENTITY, :: casts…); choose it yourself if the guess is wrong.
  2. Read the diagram. Hover over or Tab to a table to highlight its relationships; hover over a column for its full type, default and comment. Keys shows only key columns and Names only table names, for large schemas.
  3. Drag tables (or select one and use the arrow keys) to arrange them; scroll or drag the background to pan, pinch or Ctrl + scroll to zoom. Reset layout puts every table back.
  4. Check the notes under the SQL: they list foreign keys that point to tables the script does not create, and statements that were skipped.
  5. Download SVG or PNG, or open Export as text for the Mermaid and DBML versions and a list of every relationship in plain words (also as CSV).

Examples

One-to-many: each order has one customer
Input
CREATE TABLE customers (id INT PRIMARY KEY);
CREATE TABLE orders (
  id INT PRIMARY KEY,
  customer_id INT NOT NULL REFERENCES customers(id)
);
Result
customers ||..o{ orders : "customer_id"

|| at the customer: exactly one per order, because customer_id is NOT NULL. o{ at the orders: a customer can have zero or more. The line is dashed because customer_id is not part of the order’s primary key.

Optional parent: a nullable foreign key
Input
CREATE TABLE employees (
  id INT PRIMARY KEY,
  manager_id INT NULL REFERENCES employees(id)
);
Result
employees |o..o{ employees : "manager_id"

A foreign key that may be NULL gives zero or one parent (|o). A table that references itself gets a loop.

One-to-one and identifying
Input
CREATE TABLE users (id INT PRIMARY KEY);
CREATE TABLE user_profiles (
  user_id INT PRIMARY KEY REFERENCES users(id),
  bio TEXT
);
Result
users ||--o| user_profiles : "user_id"

The foreign key is the child’s whole primary key, so each user has at most one profile (o|) and the line is solid: a profile cannot be identified without its user.

DBML for a junction table
Input
CREATE TABLE posts (id INT PRIMARY KEY);
CREATE TABLE tags (id INT PRIMARY KEY);
CREATE TABLE post_tags (
  post_id INT NOT NULL REFERENCES posts(id) ON DELETE CASCADE,
  tag_id INT NOT NULL REFERENCES tags(id),
  PRIMARY KEY (post_id, tag_id)
);
Result
Table post_tags {
  post_id INT [not null]
  tag_id INT [not null]

  indexes {
    (post_id, tag_id) [pk]
  }
}

Ref: post_tags.post_id > posts.id [delete: cascade]
Ref: post_tags.tag_id > tags.id

The end of the DBML: a composite primary key goes under indexes, and each foreign key becomes a Ref with its ON DELETE action. Both links are identifying, so the diagram draws them solid.

Common uses

  • Understand an unfamiliar database before changing it: paste the schema dump and see how the tables connect.
  • Put an up-to-date diagram in a README or wiki as Mermaid, which GitHub and GitLab draw in Markdown.
  • Move a schema to dbdiagram.io or dbdocs.io as DBML, with keys, defaults, notes and references.
  • Review a migration: paste the CREATE and ALTER TABLE statements and check that every foreign key points where it should.

Limitations

  • Relationships come from declared foreign keys (REFERENCES / FOREIGN KEY). Columns that are only named like keys (user_id without a constraint) are not linked.
  • DDL cannot require a parent to have children, so the child end is always “zero or one” or “zero or more”; “one or more” never comes from SQL.
  • Views, triggers, functions, sequences and CHECK constraints are not drawn (CHECK constraints are kept in the DBML). Temporary, virtual and partition tables are left out.
  • The SQL is read tolerantly rather than validated: a statement the database would reject may still be drawn. Unreadable parts are reported with their line numbers.
  • Scripts up to 5 million characters. Very large diagrams are exported as PNG at a reduced scale (browsers limit canvas size); the SVG keeps full detail.

Privacy

Everything happens in your browser. What you enter or open here is not uploaded or stored by MySmartCoPilot.

Frequently asked questions

Which databases and statements does it understand?

MySQL and MariaDB, PostgreSQL, SQLite and SQL Server (T-SQL), including their quoting (` name , "name", [name]), comments, MySQL’s /!…/ and DELIMITER, PostgreSQL’s $$ strings and SQL Server’s GO. It reads CREATE TABLE (inline and table constraints), ALTER TABLE … ADD / DROP / MODIFY / RENAME (as dumps add keys afterwards), CREATE [UNIQUE] INDEX, PostgreSQL enum types, COMMENT ON and SQL Server’s MS_Description` properties.

How does it decide the cardinality of a relationship?

From the foreign key and the child table’s keys. If every foreign-key column is NOT NULL, each child row has exactly one parent (||); if any can be NULL, zero or one (|o). If the foreign-key columns are unique in the child — its primary key or a unique constraint lies within them — a parent has at most one child (o|, one-to-one); otherwise zero or more (o{).

What do the solid and dashed lines mean?

A solid line is an identifying relationship: the foreign key is part of the child’s primary key, like order_id in an order_items table keyed by (order_id, product_id). A dashed line is non-identifying: the child has its own key and only refers to the parent. In Mermaid they are written -- and ...

Why is a relationship missing from the diagram?

The notes under the SQL say why: usually the foreign key points to a table the script does not create (paste that table too), or its column lists do not match. A table without any foreign key is drawn on its own, below the linked tables.

Why does the Mermaid code say decimal instead of decimal(10,2)?

Mermaid’s ER syntax takes an attribute’s type as one word, and most Mermaid versions in use accept no commas in it, so decimal(10,2) becomes decimal and double precision becomes double_precision. Where that changes the type, the exact SQL type is kept in the attribute’s comment. DBML keeps the type as written.

Is my schema uploaded anywhere?

No. The SQL is read, laid out and drawn in your browser; files you open are read locally, and the exports are made on your device. The page works offline once it has loaded.

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.