A foreign key is a Data Base concept used to ensure referential integrity. A foreign key means that values in one table must also appear in another table.

The referenced table is called the parent table while the table with the foreign key is called the child table. The foreign key in the child table will generally reference a primary key in the parent table.

Each table in the application schema has a field called ID which uniquely identifies each record. Any linked tables will refer to this record, through this unique value using a foreign key.

for example,

The P2K_CM_UNITS table has a field ID which uniquely identifies a record.

The P2K_CM_JOBS table is linked to the units table through a foreign key link called DUN_ID. This link allows us to determine the unit that a job may be related to, by following the foreign key link. It also ensures that a job is not "orphaned" by having the unit record deleted.

We can know this as the alias DUN is the alias used for P2K_CM_UNITS. Table Aliases are identified in the IMTD screen or in the table P2K_AM_TABLE_DETAILS, and may also be seen on the ERD pages.

Each foreign key link is also identified with an index and constraint name which allows us to determine the relationship that is in question. The table alias that is on each side of this parent/child relationship is used in the naming of the foreign key constraint.

In the example above the foreign key constraint name would be defined from DJB (the alias for the Jobs table - the child table) and DUN (the alias for the units table - the parent table) thusly: P2K_DJB_DUN_FK1.


Notes #

Click to create a new notes page