Docs · Naming templates

Naming templates

ERDsmith names keys, constraints, indexes and foreign key columns from your project's templates, and renames them when the design or a template changes.

A naming guideline is easy to write and hard to keep by hand, and a constraint left to SQL Server gets part of its table’s name and a hex number. The Naming templates feature page shows SQL Server’s names beside the names the templates give.

The editor keeps names as you design

Every name that follows a template is rebuilt from the objects it names whenever they change, and the Output lists each rename in the entry of the change that caused it.

Rename shop.Workshop to Course and four names follow: its primary key PK_Workshop becomes PK_Course, its check CK_Workshop_Capacity becomes CK_Course_Capacity, its default DF_Workshop_Category becomes DF_Course_Category, and the foreign key in shop.Session, FK_Session_Workshop_WorkshopCode, becomes FK_Session_Course_WorkshopCode.

The table panel of shop.Workshop: under Keys and indexes PK_Workshop, under Relationships the child FK_Session_Workshop_WorkshopCode, under Checks CK_Workshop_Capacity.
shop.Workshop before the rename.
The table panel of shop.Course: PK_Course, the child FK_Session_Course_WorkshopCode and CK_Course_Capacity.
The same table renamed Course: its names follow.
The Output: Table Workshop renamed to Course, 4 names follow, then each old name and its new one in shop.Course and shop.Session: PK_Course, CK_Course_Capacity, DF_Course_Category and FK_Session_Course_WorkshopCode.
The rename's Output entry, with every name that followed it.

A key change works the same way. Add DisplayName to the alternate key AK_Member_Email and the key becomes AK_Member_Email_DisplayName. Add StartsAt to the primary key of shop.Session and PK_Session keeps its name, as PK_{Table} has no columns in it, but the column is carried into shop.Booking, whose foreign key FK_Booking_Session_WorkshopCode_SessionNo becomes FK_Booking_Session_WorkshopCode_SessionNo_StartsAt.

The Output: Unique key AK_Member_Email of Member changed, AK_Member_Email to AK_Member_Email_DisplayName; Primary key of Session set, columns carried into 1 table, FK_Booking_Session_WorkshopCode_SessionNo to FK_Booking_Session_WorkshopCode_SessionNo_StartsAt and StartsAt added.
Two key changes and the names that followed each.

Two objects can need the same name. A second index on MentorId in dbo.Member would be IX_Member_MentorId too, so it takes the next number:

The keys and indexes of dbo.Member: PK PK_Member, AK1 AK_Member_Email, IE1 IX_Member_MentorId and IE2 IX_Member_MentorId1.
The second index on MentorId is IX_Member_MentorId1.

Every template and its tokens

Click the cog beside Model, above the tree. The project settings open in the panel on the right, and Naming is their last section, after General and SQL Server: a field for each template, and under it a preview, a real name from your project and the object it names. A template is text with tokens in braces. The defaults, each with its name on the makerspace demo:

New key column
{Table}Id, the first key column added to shop.Session SessionId. Takes {Table}, {TableSingular}.
Primary key
PK_{Table}, on shop.Session PK_Session. Takes {Table}, {TableSingular}, {Columns}, {ColumnsConcat}, {FirstColumn}.
Alternate key
AK_{Table}_{Columns}, on dbo.Member AK_Member_Email. The same tokens.
Foreign key
FK_{Table}_{ParentTable}_{Columns}, from shop.Session to dbo.Member FK_Session_Member_HostId. Those tokens and {ParentTable}, {ParentTableSingular}.
Index
IX_{Table}_{Columns}, on shop.Session IX_Session_HostId. The primary key's tokens.
Default
DF_{Table}_{Column}, on dbo.Member DF_Member_JoinedOn. Takes {Table}, {TableSingular}, {Column}.
Check
CK_{Table}_{Columns}, on shop.Workshop CK_Workshop_Capacity. The primary key's tokens; a check's columns are the columns its expression names in brackets: [Capacity] > 0 gives CK_Workshop_Capacity.
Foreign key column
{ParentColumn}, in shop.Session from shop.Workshop WorkshopCode. Takes {ParentColumn}, {ParentColumnPrefixed}, {ParentTable}, {ParentTableSingular}.

What each token gives, with its value on the demo:

{Table}
The table's name: Session on shop.Session.
{TableSingular}
The table's name in the singular. The demo's names are singular already: Session.
{Columns}
The object's columns joined by _: WorkshopCode_SessionNo for the primary key of shop.Session.
{ColumnsConcat}
The same columns run together: WorkshopCodeSessionNo.
{FirstColumn}
The first of them: WorkshopCode.
{ParentTable}
The table a foreign key references: Member for the host of a session.
{ParentTableSingular}
That table's name in the singular: Member.
{Column}
A default's column: JoinedOn.
{ParentColumn}
The column a foreign key column references: WorkshopCode.
{ParentColumnPrefixed}
The parent table's singular name before the parent column, unless the column starts with it already: WorkshopCode stays WorkshopCode, and a reference to dbo.Author.Id becomes AuthorId.

A token with no value takes the _ before it along, so a check that names no column in a table Orders is CK_Orders.

Presets side by side

Preset fills every template at once. ERDsmith (IDEF1X keys) is the default above. EF Core keeps the same key, constraint and index templates, names a new key column Id and foreign key columns {ParentColumnPrefixed}, as Entity Framework Core expects. The difference shows on a schema keyed Id: two parents, dbo.Author and dbo.Book, and a child dbo.Review, each with an Id key, and a relationship drawn from each parent to the child.

-- dbo.Review: ERDsmith (IDEF1X keys)
Id: PK, FK to Author, FK to Book
PK_Review
FK_Review_Author_Id
FK_Review_Book_Id
-- dbo.Review: EF Core
Id: PK
AuthorId: FK to Author
BookId: FK to Book
PK_Review
FK_Review_Author_AuthorId
FK_Review_Book_BookId
Under ERDsmith (IDEF1X keys): dbo.Author and dbo.Book, each with Id int, and dbo.Review with one column, Id (FK) int, its box rounded; two solid lines from the parents end at Review.
ERDsmith (IDEF1X keys), drawn identifying: both lines take dbo.Review.Id.
Under EF Core: dbo.Review with Id, AuthorId (FK) and BookId (FK), two dashed lines from dbo.Author and dbo.Book.
EF Core: AuthorId and BookId beside the review's own Id.

Under ERDsmith (IDEF1X keys) both relationships want a column named Id, and the child already has an Id of the same type, its own key. Drawn identifying, both take it: the child’s own key column becomes the foreign key to both parents as well. Drawn non-identifying, ERDsmith asks for a role name instead, as a non-identifying relationship never takes a key column. Under EF Core the child gets AuthorId and BookId. The role names page covers this case. On the demo, applying EF Core renames two names: shop.Booking.WorkshopCode, which references shop.Session, becomes SessionWorkshopCode, and its foreign key becomes FK_Booking_Session_SessionWorkshopCode_SessionNo.

A preset changes nothing until you apply it; templates that match no preset read Custom.

Change a template

  1. Type the new template. The field turns orange, its label says “changed, not applied”, and the preview shows the new name beside the one it has now. Type { to list the tokens that template takes, each with its value on the preview’s object; pick one with the arrow keys and Enter, Tab or a click.
  2. The bar under the templates counts what applying would do.
  3. Apply changes renames every name that follows the template, in one step you can undo. The Output lists each rename.
The Primary key field with PK_{Table}_{ typed, its label marked changed, not applied, its preview PK_Member_... on dbo.Member and the name it has now, PK_Member, and beside it the token list: Table, TableSingular, Columns, ColumnsConcat, FirstColumn with their values on dbo.Member.
Typing { lists the tokens this template takes, with their values on the preview's table.
The bar under the templates: 1 template changed, renames 5 names, with Discard and Apply changes.
The bar counts the renames before you apply.
The Output: Primary key template PK_{Table} to PK_{Table}_{Columns}, 5 names renamed, 0 set by you kept, then PK_Member to PK_Member_MemberId, PK_MemberNote to PK_MemberNote_MemberNoteId, PK_Booking to PK_Booking_WorkshopCode_SessionNo_MemberId and 2 more.
After Apply changes: one Output entry with every rename.

A template with an error can’t be applied: an unknown token (ERDsmith names the nearest one), or a key or constraint template without {Table} or {TableSingular}, since those names must be unique in their schema. A warning, such as an index template without a columns token, still applies.

Names you set yourself

Type a name on a key, constraint or column that differs from what its template gives, and it is yours. Its field ends in an orange broken link; a name that follows its template ends in a grey link instead. A changed template leaves your names alone, and the Output counts them: “0 set by you kept” above. A click on the broken link, or a blank field, gives the name back to its template. To give back every name of one kind at once, click Reset beside its template in the project settings (“Reset 2 names”): a dialog lists each rename first.

The editor of the primary key PK_Session_Main of shop.Session: its Name field ends in an orange broken link.
A primary key named by hand: the orange broken link marks it.

Long names and clashes

SQL Server allows 128 characters in a name. With Shorten long names on, a longer generated name is cut to 128 characters, the last one ~. A name already taken in its scope takes the next number, as IX_Member_MentorId1 did above, and loses it when the clash goes.