Скачиваний:
101
Добавлен:
30.04.2013
Размер:
1.64 Mб
Скачать

Relationships and Foreign Key Attributes

Rolenames

When foreign keys migrate from the parent entity in a relationship to the child entity, they are serving double-duty in the model in terms of stated business rules. To understand both roles, it is sometimes helpful to rename the migrated key to show the role it plays in the child entity. This name assigned to a foreign key attribute is called a rolename. In effect, a rolename declares a new attribute, whose name is intended to describe the business statement embodied by the relationship that contributes the foreign key.

Foreign Key with Rolename

The foreign key attribute of “player-team-id.team-id” in the PLAYER entity shows the syntax for defining and displaying a rolename. The first half (before the period) is the rolename. The second half is the original name of the foreign key, sometimes called the base name.

Once assigned to a foreign key, a rolename migrates across a relationship just like any other foreign key. For example, suppose that you extend the example to show which PLAYERs have scored in various games throughout the season. The “player-team-id” rolename migrates to the SCORING PLAY entity (along with any other primary key attributes in the parent entity), as shown next.

Diagram Showing Migration of an FK Attribute with a Rolename

Note: A rolename is also used to model compatibility with legacy data models in which the foreign key was often named differently than the primary key.

Designing a Key-Based Data Model 4–9