dbForge Studio lets you create the following relation types: physically existing foreign key relations and virtual relations.
They represent physically existing foreign key relations between tables. On the diagram, these relations are displayed as connecting lines. Their appearance depends on the selected notation.
The following options are available for managing physical relations:
To create a relation:
1. On the Database Diagram toolbar, select New Relation.
2. Select the child table and move the mouse pointer to the parent table while holding the mouse button, then release the mouse button. A New Foreign Key dialog appears with a referenced table, a database, a constraint, and columns already set.
3. In the dialog, specify Constraint Columns.
4. To save the changes, select OK.
Note
Relations on the diagram correspond to existing foreign keys in a database. When you create a relation on the diagram, a foreign key constraint is created in the database. If the foreign key cannot be created in the database, the relation cannot be created on the diagram.
To delete a relation, select it and press the Delete keyboard shortcut. In the window that appears, select Yes to confirm the deletion.
Note
When you delete a relation from the diagram, the corresponding foreign key is deleted from the database.
To edit a relation:
1. Double-click a relation to invoke the Foreign Key Properties dialog.
2. Make changes and select OK to save the changes.
To change the relation parent table, drag the parent end of the relation to another table. You cannot change the relation child table.
Note
The relation cardinality is determined automatically from the child table constraints and cannot be changed by a user except for editing child table constraints.
Virtual relations allow you to create relations between tables if their storage engine does not support foreign keys. Virtual relations do not exist physically but are only stored on the diagram. However, they can be converted to physical foreign keys. On the diagram, they are displayed as thin dotted lines connecting tables.
You can move, bend, and reroute virtual relations, and drag a relation parent end to another table the same way as you do with physical relations.
To create a virtual relation:
1. On the Database Diagram toolbar, select New Virtual Relation.
2. Select the child table column and move the mouse pointer to the parent table column, holding the mouse button pressed, and then release the mouse button. The virtual relation appears on the diagram.
To create a virtual relation between entire tables:
1. On the Database Diagram toolbar, select New Virtual Relation.
2. Select the child table and move the mouse pointer to the parent table, holding the mouse button pressed, and then release the mouse button.
3. In the Virtual Relation Properties dialog that appears, select constraints and referenced columns.
4. To save the changes, select OK.
To edit a virtual relation:
1. Double-click the virtual relation to invoke the Virtual Relation Properties dialog.
2. In the dialog, make changes.
3. To save the changes, select OK.
To delete a virtual relation, do one of the following:
You can view, edit, remove virtual relations, generate their DDL, or convert them to foreign keys in the Virtual Relation Manager pane.
To open the Virtual Relation Manager pane, do one of the following:
On the Database Diagram toolbar, select Virtual Relation Manager.
On the View menu, select Other Windows > Virtual Relation Manager.
In the Virtual Relation Manager grid, right-click a relation you want to manage and select a required command from the shortcut menu.
Each relation has a comment - a rectangle with a relation foreign key name.
To display a comment, on the Database Diagram toolbar, select Show Comments.
By default, comments are displayed near the child end of relations. To reposition a comment, drag it to the required place, and it will move with the relation.
To hide a comment for a specific relation, select it and press the Delete keyboard shortcut. To display it again, right-click the relation and select Show Comment from the shortcut menu.
You can enable or disable a foreign key relation to control whether it enforces data rules in the database.
To enable a relation, right-click the selected relation and select Enable. This activates the foreign key, ensuring data in the child table aligns with the parent table, for example, preventing invalid references.
To disable a relation, right-click the selected relation and select Disable. This deactivates the foreign key, allowing data changes that might not follow the relation’s rules, though the relation remains defined.
Note
Disabling a relation may allow data that violates the foreign key, potentially leading to errors when the relationship is re-enabled. Use with caution.
By using Clear Waypoints, you reset the line to its default routing, allowing the diagram to automatically adjust the connection between the tables. This can be useful if the relationship line has become too complex or if you want to remove any unnecessary bends or curves in the diagram.
To clear waypoints for a specific relation, select the selected relation and select Clear Waypoints.
To adjust relation shapes, right-click the selected relation, select Shape and then select one of the following options:
To find the selected relation in Database Explorer, right-click it and select Find in Database Explorer. The foreign key is highlighted in Database Explorer.
To display the relation in Document Outline, right-click the selected relation and select Synchronize with Document Outline.
Download dbForge Studio for SQL Server and try it absolutely free for 30 days!