SQL Server

Draw an ER diagram of a SQL Server database

Script the tables from Management Studio, paste the script, and get the database as DBML that DB Planner draws as an ER diagram. It needs no connection, so it works for a database you can only reach from inside a network.

Free, no account. Your schema is converted on our server and not stored. Up to 200 KB.

Get the script out of Management Studio

  1. Right-click the database, then Tasks, then Generate Scripts.
  2. Choose Select specific database objects and tick Tables.
  3. Under Advanced, set Types of data to script to Schema only, and leave Script Foreign Keys and Script Indexes on.
  4. Save to a single file, or to a new query window, and copy it.

What an SSMS script contains, and what happens to it

  • Bracketed, schema-qualified names. [dbo].[Orders] becomes the table Orders in a document named dbo. A database with several schemas gets a document for each.
  • GO batch separators are understood as the ends of statements.
  • CONSTRAINT [PK_...] PRIMARY KEY CLUSTERED becomes the primary key, keeping its constraint name.
  • WITH CHECK ADD CONSTRAINT ... FOREIGN KEY becomes a relationship. WITH NOCHECK is read the same way, and the CHECK CONSTRAINT line that follows each one is ignored.
  • CREATE NONCLUSTERED INDEX becomes an index on its table, with its name.
  • Types such as nvarchar(255), datetime2(7), and bit are kept as written.

Views, stored procedures, functions, and triggers are not tables and are left out. Extended properties are not read, so column descriptions stored with sp_addextendedproperty do not become notes.

One schema, from the database to the code

For a .NET team the script is rarely the only description of the schema: there is an Entity Framework model beside it. DB Planner reads both, so you can diagram an EF Core model the same way and see where the two disagree, and it exports a design back out as SQL Server DDL or as C# model classes.

Like PostgreSQL, SQL Server does not index a foreign key for you; the schema checker lists the ones without. The same route works for PostgreSQL and MySQL.

SQL Server ER diagram questions

How do I generate an ER diagram from a SQL Server database?

In SQL Server Management Studio, right-click the database, choose Tasks, then Generate Scripts, and script the tables as schema only. Paste the script above to turn it into DBML, and paste the DBML into a DB Planner project.

How is this different from Database Diagrams in SSMS?

An SSMS diagram lives inside the database and needs SSMS and access to that server to open. A DB Planner diagram is drawn from a script, opens in a browser, and can be shared with people who have no database access at all. It is also text, so a change can be reviewed.

Are foreign keys read from an SSMS script?

Yes. SSMS writes each one as ALTER TABLE ... WITH CHECK ADD CONSTRAINT ... FOREIGN KEY after the tables, and those are read into relationships with their names and delete rules.

What happens to IDENTITY columns?

The identity specification stays with the column type, so an int IDENTITY(1,1) column is shown as exactly that. Nothing about the seed or the increment is lost.

Put your schema on the board

Start on the free plan, no card needed. Pro is $5 a month when you outgrow it.

Start designing free