ER diagram generator: from SQL to a picture

Paste CREATE TABLE statements and get an ER diagram of the tables, keys and relationships, ready for a review, a chat, a blog post or a slide.

  • SQL Server (T-SQL)
  • No account
  • Free

Draw a diagram

Picture options
Picture of Main: dbo.Member, shop.Booking, shop.Workshop; a legend of its lines and marks under it; a header with erdsmith.com/sql-to-erd, and ERDsmith.
Open in ERDsmith
Read 3 tables.
No errors, nothing left out.

Share the diagram

Post the picture, and add the link if you want readers to open the diagram and explore it. The link is a snapshot that holds your SQL, so anyone with it can see the script.

Opens this page with your SQL in the box and the diagram drawn.

Put the downloaded erd.png next to the file. The picture links to the diagram.

How it works

  1. 01Paste your scriptCREATE TABLE statements from SSMS "Generate Scripts", a SQL Database Project or an EF Core migration script.
  2. 02See the diagramMicrosoft's own T-SQL parser reads it in your browser, and the tables are laid out for you with the relationship lines between them.
  3. 03Take it with youCopy the picture, download it as SVG or PNG, or copy a link that opens this page with the same script. A link is a snapshot: what someone changes after opening it stays with them.

What the diagram shows

Each table with its schema and columns, and their types in the ERDsmith and IE looks. The primary key sits above the line; foreign key columns carry (FK) and alternate keys (unique constraints and unique indexes) (AK). Every foreign key becomes a relationship line in crow's foot or IDEF1X notation, composite keys included, and a table whose key holds its parent's key gets round corners. What SQL Server would refuse is marked on the table and listed under the picture.

Highlight what your text is about

A diagram in a blog post, a code review or a README is usually there for one part of it: the foreign key the post explains, the table a change touches. Type their names in Highlight and the picture draws those tables, columns or foreign keys highlighted, so the reader looks there first. Write them as the script does; brackets are optional, a table's schema too where its name is unique, and case doesn't matter. The picture you copy or download keeps the highlight, and so does the link to the diagram.

Questions

What is it for?

Quick pictures of a few tables and how they connect: for a code review, a chat, a blog post or a slide. To design a database, open the diagram in ERDsmith.

Can I remove the ERDsmith header?

No. The header names this page and ERDsmith, and every picture made here carries it. The editor's picture export puts your project's and diagram's names in it instead.

Which databases does it read?

SQL Server's T-SQL. A batch with a syntax error is left out with its line named, and the rest of the script is drawn; a script written for another database draws as far as its batches read as T-SQL.

Can I move tables or change the design?

Not on this page: it draws the script as it is and lays the tables out for you. Open in ERDsmith takes the script into the editor, where you move tables and change the design under SQL Server's rules.

How big can the script be?

There is no set limit: the script is read on your computer and never sent anywhere. A big script takes longer to lay out, and a picture of many tables is hard to read. A link holds about 20 tables as SSMS writes them; past that, download the picture instead.

How do I get the script from my database?

In SSMS, right-click the database, pick Tasks, then Generate Scripts, and script the tables to a new query window. For an EF Core project, dotnet ef migrations script writes one. Files from a SQL Database Project work too: paste them one after another.