In Toad Data Modeler, you can link parent and child entities:
- Through a Key (Primary or Alternate key) of parent entity
- Through Unique Index of parent entity
To set a linking method
- Double-click the selected relationship.
- From the Parent Key box, select the appropriate linking method.
Toad Data Modeler creates new alternate keys for unique attributes automatically.
Example: There are two attributes in the T_GENRE entity.
No alternate key exists in this entity.
Edit the Name attribute and select the Unique checkbox.
New alternate key has been added to the entity automatically.
As soon as you create a relationship in Toad Data Modeler, foreign keys are created automatically in the child entity (automatic key migration).
There are two types of foreign keys:
- Foreign keys (FK, graphically marked by green key by default)
- Primary Foreign keys (PFK, graphically marked by blue key by default)
The type of FK depends on what relationship you create, see Relationship Types for more information.
Synchronization of Not Null and Mandatory Parent
Select Settings | Options | Physical Model | General tab | Synchronize Not Null with Mandatory Parent.
By default, this checkbox is selected. You can change the settings during your modeling, the new setting will be used by default in all new items you create in your model.
- Synchronization enabled: If cardinality has set Mandatory Parent, a FK attribute will be automatically Not Null. If you clear the Not Null checkbox of the FK attribute, Mandatory Parent option will be unchecked.
- Synchronization disabled: If you uncheck the Not Null checkbox of a FK attribute, the Mandatory Parent current status remains unchanged.
Foreign Keys in the Attribute Properties Dialog
If you open the Attribute Properties dialog | Foreign Keys tab, you can see details on particular foreign key:
- Name of the parent entity
- Name of relationship connecting the parent and child entity
- Name of PK Attribute
Foreign Keys in the Relationship Properties Dialog
In the Relationship Properties dialog | Foreign Keys tab, you can set a linking method between parent and child entities.
See Select Parent Key for Relationship for more information on available linking methods.
In Toad Data Modeler, you can control your foreign keys. Foreign keys mapping feature allows you to create Compound Keys, use existing keys etc.
In the Genre entity, there is a Genre ID attribute (primary key), and in the Film entity the Genre ID attribute exists too.
If you create a new relationship between the two entities, a new foreign key will be created automatically.
Solution: Map the newly created foreign key:
- Double-click the new relationship to edit it.
- Click the Genre ID item in the Child column to expand the combo-box with other attributes of the child entity.
- Select the first Genre ID item and confirm OK.
- Result: There is only one Genre FK in the Film attribute.
TIP: To restore the original foreign key later, go to the Relationship Properties, double-click the genre_id item in Child column and select genre_id (New). This created a new genre_id Foreign Key instead of mapping it to the already existing genre_id attribute.
Automatic FK Mapping
You can also set Automatic FK Mapping in Settings | Options | Model | Physical Model.
- Disable - FK mapping is OFF
- Enable - Toad Data Modelersearches for matching attributes. If a single possible mapping option is found, the FK is mapped. If multiple possible mapping options are found, a dialog appears where you choose the attribute the FK should be mapped to.
- Always Show Dialog - Displays a dialog whenever there is one or more possible mapping options. You get to choose the attribute the FK should be mapped to.