Creating a foreign key

A foreign key is a key used to link two relational database tables. It is a field or a group of fields in one table that uniquely identifies a row of another table (primary key).

  1. To create a foreign key, right-click on the entity that will contain this field and select Actions > Create Foreign Key.

    12124222_429x455

  2. A wizard will appear where you fill in all necessary fields. A Foreign Entity is the entity that you want your entity to link to. Foreign Field is in most cases the ID field (it must be a field that will uniquely identify the row). If you have a Lookup that you want to use for the foreign key you can select it from the drop-down list (it will e.g. show a customer’s name based on his ID). Check or uncheck the box Allow Nulls depending on your preferences (if the foreign key field can remain empty or not). The FK Field Name is automatically created from the names of the foreign entity and field. It is recommended not to change it, because it shows the path to the referenced field. Use Caption for your description of the field. After filling the fields, click on OK.

    12124223_576x264

  3. A model editor prefilled by the wizard will open and you can edit other attributes. Save when finished.

    Note that the foreign key is a normal database field, only with the ForeignKey attributes filled in and DataType set to UniqueIdentifier.