Use Macros to Create Logical to Physical Relationship Names

When enforcing a Foreign Key Constraint Name Standard you can use macros to create Logical to Physical relationship names.

The default for mapping a logical relationship to a physical relationship is to follow the convention, <entity parent name><R/number><entity child name> maps to <table parent name><R_number><table child name>. Each relationship is assigned a number, based on the order in which it was created.

For example:

In the logical model: Grandparent R/1 Parent

In the physical model: Grandparent R_1 Parent

You can use the Name Mapping options to establish another convention for the inherited name. For example, you might want the relationship name created from the table names in the relationship.

To use macros to create logical to physical relationship names

  1. Click Model Naming Options on the Actions menu.

    The Model Naming Options dialog opens.

  2. Select the Name Mapping tab, enter the %Parent_%Child macro in the Relationships box, and click OK.

    The macro is used to create logical to physical relationship names.

This creates relationship names in the physical model based on a combination of the parent and child table names. For example, in a model in which the parent table is named Grandfather and the child table is named Parent, the following relationship name would result: Grandfather Grandfather_Parent Parent.

Your change would be reflected in the Relationships dialog on the physical side of your model.

You can refine the use of macros in this context, to address other issues that may be relevant. For example:

Long table names may exceed the limits of the allowable string length for constraint names. To prevent this problem, you could modify the macro as follows:

%Substr(%Parent,1,5)_Substr(%Child,1,5)

This macro takes a substring from the variable string at the specific location for a specified length. This example indicates the substrings Parent and Child, and allows five characters, starting at position 1.

The relationship that results is:

Grandparent Grand_Paren Parent

A case may exist where there are two relationships between the same two tables (such as one identifying and one non-identifying). You can modify the %Substr(%Parent,1,5)_Substr(%Child,1,5) macro to indicate the relationship type using %RelType.

For example, this macro returns the relationship type at the end of the relationship name.

[Relationship type valid values and their definitions include: RT_ID (identifying), RT_NI (non-identifying), RT_SC (subtype), or RT_MM (many-to-many).] You can shorten the length of the relationship name by removing the "RT" portion of the relationship type. You implement this through the %Substitute macro:

%Substr(%Parent,1,5)_Substr(%Child,1,5)%RelType

for a non-identifying relationship it returns:

Grandparent Grand_ParenRT_NI Parent

%Substr(%Parent,1,5)_Substr(%Child,1,5)%Substitute(%RelType,RT_,_)

returns

Grandparent Grand_Paren_NI Parent

Another case may exist where there are two relationships between the same two tables (such as one identifying and one non-identifying). You can modify the %Substr(%Parent,1,5)_Substr(%Child,1,5) macro to indicate the relationship type using %RelType.

For example, this macro returns the relationship type at the end of the relationship name.

[Relationship type valid values and their definitions include: RT_ID (identifying), RT_NI (non-identifying), RT_SC (subtype), or RT_MM (many-to-many).] You can shorten the length of the relationship name by removing the "RT" portion of the relationship type. You implement this through the %Substitute macro:

%Substr(%Parent,1,5)_Substr(%Child,1,5)%RelType

for a non-identifying relationship returns:

Grandparent Grand_ParenRT_NI Parent

%Substr(%Parent,1,5)_Substr(%Child,1,5)%Substitute(%RelType,RT_,_)

returns

Grandparent Grand_Paren_NI Parent