Docs · Role names

Role names

A role name says what a foreign key column is for, such as MentorId for a member's mentor. ERDsmith asks for one when a second column would need a name the child already has.

Why a column needs a role name

A table can’t hold two columns named MemberId, and a numbered MemberId2 says nothing; a role name such as AuthorId says what the second one is for. Why the editor writes foreign key columns for you and keeps them in step is on the database modeling page.

ERDsmith writes a role-named column as the role name, a period and the name it migrated from, the form IDEF1X (FIPS 184) uses: AuthorId.MemberId. So the box says both what the column means and which key it holds.

Two references to one parent

Draw a second line from dbo.Member to dbo.MemberNote, which has its MemberId from the first one, and ERDsmith asks for a role name for the new column before it adds it. Its default, when nothing is asked, is the column’s name and 2: MemberId2.

The dialog MemberId is already in dbo.MemberNote: the change to dbo.Member.MemberId carries a column MemberId into dbo.MemberNote, which has its MemberId from another relationship on the same key; Give the new column a role name, filled with AuthorId; Don't ask again; Cancel and Apply.
A second relationship on the same key asks for a role name.

To spot two references on a diagram, look for two lines between the same two boxes; they show apart once the diagram is arranged (Arrange, under the diagram), and role.base says which column each one fills.

dbo.Member and dbo.MemberNote with two dashed lines between them; dbo.MemberNote lists MemberId (FK) and AuthorId.MemberId (FK).
Two lines from dbo.Member: MemberId and AuthorId.MemberId.

A role name helps with one reference too: in the demo, shop.Session’s HostId (HostId.MemberId with Role names as role.base on) is the member who runs the session, which a column named MemberId wouldn’t say.

A relationship to its own table

A self-reference, such as a member’s mentor, migrates MemberId into dbo.Member, which already has it. So the column gets Parent before its name: a line drawn from dbo.Member to itself adds ParentMemberId. Rename it to say what the parent row is: the demo’s is MentorId. The relationship stays non-identifying, since its column can’t be part of the table’s own primary key, and its panel shows Identifying disabled, the “?” beside it saying why.

The dbo.Member box: MemberId, Email (AK), DisplayName, JoinedOn, MentorId.MemberId (FK), RowVer and Bio, with the mentor line leaving its right side and coming back.
dbo.Member: MentorId is the role name, MemberId the key it holds.
The relationship panel of FK_Member_Member_MentorId, General folded: parent key PK_Member (MemberId), Identifying unticked and disabled with a question mark beside it, Optional: MentorId allows NULL, and under Columns the parent column MemberId with its role name MentorId and an orange broken link.
The mentor relationship: non-identifying, its column's role name MentorId.

One reference by the primary key, one by an alternate key

The relationship panel’s Parent key lists the parent’s primary key and its alternate keys. Switch the second relationship above from PK_Member to AK_Member_Email and its column changes with the key: AuthorId goes, and the relationship adds Email, as the Foreign key column template names it. dbo.MemberNote has no Email yet, so nothing is asked. Rename the column AuthorEmail and that becomes its role name, written AuthorEmail.Email; the foreign key’s name follows.

dbo.Member and dbo.MemberNote, arranged, with two dashed lines between them; dbo.MemberNote lists MemberId (FK) int and AuthorEmail.Email (FK) nvarchar(254).
Two lines from dbo.Member: MemberId holds its primary key, AuthorEmail.Email its alternate key Email.
The Output: Parent key of FK_MemberNote_Member_AuthorId changed, columns carried into 1 table, FK_MemberNote_Member_AuthorId to FK_MemberNote_Member_Email, Email added, AuthorId gone; Column MemberNote.Email renamed to AuthorEmail, FK_MemberNote_Member_Email to FK_MemberNote_Member_AuthorEmail.
The key switch and the rename, each with the names that followed.

Two parents keyed Id

Under the default Foreign key column template, {ParentColumn}, a reference to a key named Id needs a column named Id. Draw a line from dbo.Author and one from dbo.Book to dbo.Review, all three keyed Id, with Identifying, and nothing is asked: a key column with the name and type an identifying relationship needs is taken, not added. Both relationships take dbo.Review.Id, the review’s own key, so each review’s id now has to match an author’s and a book’s. The Output says so; watch for it on any schema keyed Id. Drawn with Non-identifying, the same lines ask instead (below), as a non-identifying relationship never takes a key column.

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.
Both lines take dbo.Review.Id: one column, two parents, two identifying lines.
The Output: Review.Id joined FK_Review_Author_Id, it has the name and type the relationship needs; the same for FK_Review_Book_Id.
The Output tells each join.

Two ways out. The EF Core preset names foreign key columns {ParentColumnPrefixed}, so the same lines add AuthorId and BookId and the review keeps its own Id. Or key the child ReviewId and rename each foreign key column as you draw it: AuthorId and BookId become role names, written AuthorId.Id and BookId.Id.

Under the EF Core preset: dbo.Review with Id, AuthorId (FK) and BookId (FK), two dashed lines from dbo.Author and dbo.Book.
EF Core: AuthorId and BookId, no role names.
Under the default preset: dbo.Review with ReviewId, AuthorId.Id (FK) and BookId.Id (FK), two dashed lines from dbo.Author and dbo.Book.
The default preset, columns renamed: AuthorId.Id and BookId.Id.

A clash with a column of another type

When the column a relationship would add has the name of a column the child already has with another type, or on the other side of the primary key (a key column in the way of a non-identifying relationship, a column outside the key in the way of an identifying one), ERDsmith asks: give the new column a role name, suggested as the parent table’s name before the column’s, or rename the existing column when it is the table’s own and no relationship added it. Cancel leaves the model as it was. With “Don’t ask again” ticked, every later clash in the session takes a role name without asking: the column’s name and 2.

The dialog Status is already in shop.Booking: the change to shop.Session.WorkshopCode carries a column Status into shop.Booking, which has its own Status, tinyint; Give the new column a role name, filled with SessionStatus and picked; Rename the existing column, BookingStatus; Don't ask again; Cancel and Apply.
Naming shop.Session.WorkshopCode Status would carry a Status into shop.Booking, which has its own of another type.

Give a column a role name

  1. Draw the relationship with Identifying or Non-identifying, from the parent’s box to the child’s, or find a column it added: pick the child table in the tree, then the column in the table panel’s list. In its column panel the Type is locked, with a link to the parent column at its end.
  2. Type the role name in Name and press Enter. A name another column of the table has takes the next number.
  3. The column is written role.base in the table panel’s list, and on the diagram while Role names as role.base is on; the foreign key’s name follows.
  4. To give the column back its template’s name, click the orange broken link at the end of the field, or clear the field.

Does a column follow its template?

A migrated column either follows the Foreign key column template or has a role name, and the editor shows which:

  • In its column panel, a name that follows the template ends in a grey link; a role name ends in an orange broken link, its tooltip “Written by you, a role name”. A click on the broken link, a blank field or the template’s own name clears the role name.
  • In the table panel’s column list, and on the diagram while Role names as role.base is on, a role-named column is written role.base.
  • After a rename, the Output names the column and every name that followed: “Column [MemberNote].[Email] renamed to [AuthorEmail]: 1 name follows.”
The column panel of dbo.MemberNote.MemberId: its Name MemberId ends in a grey link, its Type int is locked with a link to the parent column.
MemberId follows its template: a grey link.
The column panel of dbo.Member.MentorId: its Name MentorId ends in an orange broken link, its Type int is locked with a link to the parent column.
MentorId is a role name: the orange broken link.

role.base on the diagram

Each diagram has its own display settings: Display, at the right of the diagram tabs, opens them in the panel on the right. Role names as role.base is off by default, and the look presets leave it as it is. It helps where a column’s name doesn’t show the key it holds: renamed columns such as MentorId.MemberId and AuthorEmail.Email, a design review, readers who know IDEF1X.

It helps less on a schema keyed Id under the default preset, where every renamed foreign key column reads AuthorId.Id, BookId.Id, and the .Id says nothing new. Turn the setting off and the columns read AuthorId and BookId, or use the EF Core preset, whose AuthorId follows its template and has no role name.

Role names and the naming templates

The Foreign key column template names every migrated column without a role name. A column with a role name keeps it when that template changes, which the project settings say beside the template: “role names kept”. Reset never takes role names back in bulk; clear them one column at a time.

Settings and defaults

Where ERDsmith asks
A second relationship between two tables on the same parent key, and a column of another type, or on the other side of the primary key, already in the way: "MemberId is already in dbo.MemberNote".
The default role name
The column's name and 2, taken without asking when nothing asks: MemberId2.
A self-reference
Parent before the column's name, without asking: ParentMemberId.
A clash's suggestion
The parent table's name before the column's: SessionStatus.
Don't ask again
Every later clash in the session takes the default role name: Status2.
Role names as role.base
A display setting of each diagram, off by default: MentorId, on MentorId.MemberId.
Foreign key column template
{ParentColumn} by default, "role names kept": a column with a role name keeps it when the template changes, MentorId stays.