SQL SERVER · EF CORE

SQL Server database diagrams: import, design, export

Bring a script in, see it as a diagram, change it under SQL Server's rules and take clean DDL back out. In your browser.

01 · Import

Paste a script, get a model

SSMS's Generate Scripts or dotnet ef migrations script. Preview first; anything it leaves out, a view, a trigger, the data, is listed with its line.

The Import DDL tab with an EF Core migration script: the script, and a preview of 5 tables and 2 schemas created, 4 statements skipped.

02 · Diagram

Every table, key and relationship, drawn

Arranged for you, in crow's foot or IDEF1X, with SQL Server's types and what a SQL Server check finds marked on the table.

The diagram: dbo.Members, dbo.MemberNotes, shop.Workshops, shop.Sessions and shop.Bookings with their keys, types and relationships.

03 · Change

Change one thing, the rest follows

Rename Members to Member and seven names follow, every one listed. Foreign key columns keep in step with their keys.

The diagram after dbo.Members is renamed dbo.Member.The Output: Table Members renamed to Member, 7 names follow, each name before and after.

04 · Export

Clean DDL back out

Parents first, each table with its keys. A table SQL Server would refuse is held back with the foreign keys into it; the rest goes out.

SQL Server's data types

Each column takes one of SQL Server's own types, with the length, precision and scale the type has: nvarchar(200), decimal(9, 2), datetime2(3). A foreign key column takes its key's type, length, precision and scale, and follows when the key changes. More in how to pick each column's type.

Checked against SQL Server's rules

The SQL Server check reads the model on every change and marks each table with what SQL Server would refuse. A name over 128 characters (103), a json column in a project set to SQL Server 2022 (2715), a key or unique index on an nvarchar(max) column (1919): each is marked on its table as you make it.

dbo.Members marked with one problem: its unique index IX_Members_Email is on Email, an nvarchar(max) column, which a key can't hold.

Never built, so there is nothing to mark: 1778 a foreign key column of another type than its key.

SQL projects in and out

Import DDL reads one script, pasted or from a file, or a folder of .sql files, such as a SQL Database Project's, joined and read as one script.

Export DDL writes one script, parents first, or, in Chrome and Edge, a folder with a file per table in the layout SqlPackage writes, rewriting only the files that change.

EF CORE

EF Core migration scripts

  • Imports the script dotnet ef migrations script writes as a diagram, an idempotent one (--idempotent) too.
  • The EF Core naming preset: a key named Id gives foreign key columns like CustomerId, as EF Core expects.
  • Leaves EF's own __EFMigrationsHistory and the data out of the diagram.

More: SQL Server articles · Templates · Docs