4D v16.3

Creating and modifying relations

Home

 
4D v16.3
Creating and modifying relations

Creating and modifying relations  


 

 

You can create or remove relations via the Structure editor or using the SQL commands of 4D. This section covers the manual creation of relations in the Design environment. For more information about using SQL statements in 4D, please refer to the 4D SQL Reference manual.

You can create a relation between two tables by manually tracing a line between two fields or using the add objects menu of the tool bar. 

To create a relation using the Structure editor window:

  1. In the Structure editor window, move the pointer over the foreign key field for this relation.
  2. Hold down the mouse button and drag toward the table to be related.
    As you move the pointer, 4D selects the field and draws the relation, as shown below.
  3. Drag to the primary key field in the One table and release the mouse button.

To create a relation using the add objects menu:

  1. Select two fields of the same type belonging to two different tables.
    The order of selection will determine the direction of the relation. The first field selected is considered as the foreign key (Many field) and the second as the primary key (One field).
  2. In the add objects menu of the Structure editor tool bar, choose the Relation option.

4D displays the relation as an arrow between the two tables in the Structure editor. The shape of the beginning and end connectors as well as the N and 1 characters shown within them indicate the direction of the relation:

The Inspector palette displays the properties of the relation (see Relation properties).

The appearance of relations is different when they have been generated via SQL (square shaped connectors):

4D lets you delete a relation at any time. To do so:

  1. Select the relation to be deleted.
    When a relation is selected, its outline turns blue.
  2. Right-click on the relation and choose the Delete command from the context menu.
    OR
    Press Delete or Backspace.

In both cases, a warning dialog box appears so that you can confirm or cancel the operation. If you confirm it, 4D removes the linking arrows and the tables are no longer related. Any indexes of Many and One fields are not deleted.

You can reestablish any relation at any time. You would do so, for example, if you mistakenly draw the relation between the wrong fields or if you want to change a relation property. 4D lets you reestablish a relation simply by drawing the relation line again.

In the case of complex structures, you can select fields in the source and destination tables of a relation using the Select Source Field and Select Destination Field commands, located in the context menu of the relation.

To reestablish a relation using the same two fields, double-click on the relation in the Structure editor. 4D displays the relation properties in the Inspector palette so that you can make any necessary changes.
To reestablish a relation using a different field in the One table, redraw the relation beginning from the Many field.
To reestablish a relation using a different field in the Many table, first remove the faulty relation and then draw the correct relation line again.

 
PROPERTIES 

Product: 4D
Theme: Creating a database structure

 
HISTORY 

 
ARTICLE USAGE

4D Design Reference ( 4D v16)
4D Design Reference ( 4D v16.1)
4D Design Reference ( 4D v16.3)