Skip to content

Foreign key

A foreign key protects a defined reference between records through matching key values.

Software Development

Protect references to existing records

A foreign key is a database constraint for a reference to a matching key in the referenced table. In a fictional example, a service note points to an existing job. A reference value that is not NULL must not then point to an unknown job identifier.

Whether the reference may be absent is defined separately. Also clarify what should happen when the referenced record changes or is deleted. A foreign key does not automatically mean dependent data is deleted too. It protects the reference, but does not decide whether the note belongs to the job in business terms or whether the person editing may access it. Those rules need their own checks.

Sources

Articles on this topic

Software Development with ASES

Custom software, web and mobile apps