ER diagram to SQL, as one script or a folder

Writing the script by hand after the drawing means typing every key again and getting the order right. ERDsmith writes it from the model: parents first, each table with its keys.

The demo's Main diagram as a picture: a header with makerspace, Main and ERDsmith, then dbo.Member, dbo.MemberNote, shop.Workshop, shop.Session and shop.Booking with the lines between them, and a legend under them.
The diagram. The demo's Main diagram as Export diagram draws it: five tables in two schemas and the six relationships between them.
-- Table [shop].[Workshop]
CREATE TABLE [shop].[Workshop] (
    [WorkshopCode] CHAR (4)       NOT NULL,
    [Title]        NVARCHAR (80)  NOT NULL,
    [Capacity]     SMALLINT       NOT NULL,
    [Price]        DECIMAL (9, 2) NOT NULL,
    [Category]     NVARCHAR (30)  CONSTRAINT [DF_Workshop_Category] DEFAULT (N'general') NOT NULL,
    CONSTRAINT [PK_Workshop] PRIMARY KEY CLUSTERED ([WorkshopCode] ASC),
    CONSTRAINT [CK_Workshop_Capacity] CHECK ([Capacity]>(0) AND [Capacity]<=(40))
);


GO

-- Table [shop].[Session]
CREATE TABLE [shop].[Session] (
    [WorkshopCode] CHAR (4)      NOT NULL,
    [SessionNo]    INT           NOT NULL,
    [StartsAt]     DATETIME2 (0) NOT NULL,
    [DurationMin]  SMALLINT      NOT NULL,
    [EndsAt]       AS            (dateadd(minute,[DurationMin],[StartsAt])),
    [HostId]       INT           NULL,
    CONSTRAINT [PK_Session] PRIMARY KEY CLUSTERED ([WorkshopCode] ASC, [SessionNo] ASC),
    CONSTRAINT [FK_Session_Member_HostId] FOREIGN KEY ([HostId]) REFERENCES [dbo].[Member] ([MemberId]),
    CONSTRAINT [FK_Session_Workshop_WorkshopCode] FOREIGN KEY ([WorkshopCode]) REFERENCES [shop].[Workshop] ([WorkshopCode])
);
The script. Part of what Export DDL writes for it: shop.Workshop, then shop.Session's CREATE TABLE with its foreign keys; dbo.MemberNote, written between them, is left out here.

01 · Navigate

Click a table, see its script

In the Export DDL tab a click on a table marks its block in the script, from its comment to its last statement.

The Export DDL tab: the tables list of makerspace with Session picked, and beside it the script scrolled to shop.Session's block, marked from its comment to its last statement.

02 · One script or a folder

One script, or one file per table

Write the project as one script, parents first, or in Chrome and Edge into a folder: one file per table, laid out as SqlPackage writes a SQL project.

The Export panel: Write to One script or A folder, one file per object, the folder picked and makerspace-db chosen; Foreign keys and Schemas ticked; 6 new, and only files that change are rewritten.

03 · Errors

A table with an error stays out

A table with an error from the SQL Server check is held back with the foreign keys into it; the rest exports.

The tables list after the mentor relationship deletes on CASCADE: Member under dbo marked held back, the other tables without a mark.

04 · Changes

See what changes before it's written

Against a folder, each file is tagged new, modified or dropped, and only the files that change are written.

The tables list once shop.Workshop is renamed Course, against the folder written before: Course tagged new, Session modified, Workshop dropped, the others untagged.

By hand or from the model

By handIn ERDsmith
Table orderworked out by hand, parents before childrenparents first: it runs on an empty database in one go
Foreign keystyped again from the lines on the drawingwritten from the relationships, in each table's block
A renamed table's constraintsfound and renamed in every scriptrenamed with it where they follow your naming templates; in a folder, the new file tagged new and the old one dropped
A table with an errorfound when SQL Server refuses the scriptheld back with the foreign keys into it; the rest exports
A database project foldera file per table, created and kept up by handone file per table as SqlPackage lays them out; only changed files written

More on this