Working with Relations

dbForge Studio allows creating two types of relations: physically existing foreign key relations and virtual relations.

Physical 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.

Options available for managing physical relations are as follows:

  • Move - click the relation and drag its bend handle.
  • Bend - click the relation and drag its bend handle.
  • Reroute - right-click the relation and choose Reroute on the shortcut menu. The relation will be rerouted to its default route.
  • Drag a relation parent end to another table - you may attach the parent edge to any edge of the table shape.

How to Delete a Relation

Click a relation and press the DELETE key, then click Yes in the appeared dialog box.

Note

When you delete a relation from the diagram, the corresponding foreign key is deleted from the database.

How to Edit a Relation

  1. Double-click a relation to invoke the Foreign Key Properties dialog box.
  2. Make changes and click OK.

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.

How to Create a Relation

  1. Click the New Relation icon on the Database Diagram toolbar.
  2. Click the child table and move the mouse pointer to the parent table while holding the mouse button, then release the mouse button. A partially initialized New Foreign Key dialog box will appear with a referenced table, a database, a constraint, and columns already set.
  3. Specify the Constraint Columns in the dialog box and click 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.

Virtual relations

They allow you to create relations between tables if their storage engine does not support foreign keys. Virtual relations do not exist physically, but 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, reroute virtual relations, drag a relation’s parent end to another table the same way as you do with physical relations.

How to Create a Virtual Relation

  1. Click the New Virtual Relation icon on the Database Diagram toolbar.
  2. Click the child table and move the mouse pointer to the parent table. Click a required column in the child table and, holding the mouse button pressed, select a required column in the parent table, then release the mouse button. The virtual relation will appear on the diagram.

You can also select entire tables to create a virtual relation between them. In this case, the Virtual Relation Properties dialog box will appear where you should select constraints and referenced columns.

How to Edit a Virtual Relation

  1. Double-click it to invoke the Virtual Relation Properties dialog box.
  2. Make changes and click OK.

How to Delete a Virtual Relation

Do either of these actions:

  • Click it on the diagram and press the DELETE key.
  • Select it in the Virtual Relation Manager window and press the DELETE key.

How to Manage Virtual Relations

Use the Virtual Relation Manager window to view, edit, remove virtual relations, generate their DDL, convert to Foreign keys, etc.

To open it, click the Virtual Relation Manager icon on the toolbar or, on the View menu, point to Other Windows, and click Virtual Relation Manager. Right-click a required relation in the grid and select a required command on the menu.

Relation Comments

Each relation has a comment - a yellow rectangle with a relation foreign key name. Select the Show Relation Comment check box in the diagram options or click Show Comments on the Diagram toolbar to display comments. By default, they are displayed near the child end of relations. You can drag them to any other place, and they will move with the relation. To hide a comment for a specific relation, click it and hit the DELETE key. To display it again, right-click the relation and select Show Comment on the shortcut menu.