Please enable JavaScript to view this site.

R:BASE 11 Help

Like a primary key, a foreign key is a column or a group of columns. Foreign keys are also used to ensure that only valid data is entered into a column. A foreign key matches the values in a particular primary key or unique key constraint which is defined in a different table.

 

Primary and foreign keys must also match in terms of the specified columns. If you have a multi-column primary key, you can not have single column foreign keys reference it. If you have a multi column foreign key, it cannot reference a single column primary key. When a primary key is defined as more than one column, those columns are treated as a whole. Primary and foreign keys must match exactly. Thus, if your primary key is defined as text, then the corresponding foreign keys referencing it must also be text.

 

Primary and foreign keys automatically preserve referential integrity. You cannot delete a row from a table with a defined primary key if there are referenced foreign keys, thus you can never have detail records without a matching master record.

 

You can delete a row from a table with a foreign key. You cannot add a row to table with a foreign key defined unless the value entered matches a value in the referenced key table.

 

By default, users cannot update a primary key value if there are references, thus ensured that linking columns always match. The same applies for updating primary key values if there is not matching values in the referenced foreign key. However, implementing the r:base Cascade feature on primary keys will allow such changes. When a primary key is defined as a "cascading" primary key, the referenced foreign key values are automatically updated, deleted, or both. This allows the ability to update or delete referenced primary key values and retain the referential data integrity.

 

Notes:

 

A Primary Key can exist without a Foreign Key, but a Foreign Key cannot exist without a Primary Key.

A Foreign Key is always defined to reference a Primary Key or Unique Key.

A Foreign Key automatically checks that the values in the Foreign Key exist in the referenced key.

Many Foreign Keys can be defined in one table, and many Foreign Keys in different tables can reference the same Primary Key.

Once Primary and Foreign Keys are defined accordingly, R:BASE automatically preserves the referential data integrity.

A Foreign Key replaces a "Verify a value RULE".

An index is automatically built when a Foreign Key constraint is defined.

It is recommended to delete rules and indexes that are no longer needed before defining a Foreign Key constraint.