How to work 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 from the shortcut menu. The relation will be rerouted to its default route.
  • Drag a relation’s 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.

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’s parent table, drag the parent end of the relation to another table. You cannot change the relation’s 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

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 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 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 from 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 from the shortcut menu.

Download dbForge Studio for SQL Server and try it absolutely free for 30 days!

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All Features

All features

Get acquainted with the rich features and capabilities of the Studio in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Studio for your business, request a demo to see it in action.
Ready to start using dbForge Studio for SQL Server?