Junior
What guarantees does a foreign key provide for data in a relational database?
sobes.tech AI
Answer from AI
A foreign key in a relational database guarantees data integrity between two tables. It ensures that the value in the foreign key column corresponds to an existing value in the related table (usually in the primary key). This prevents:
- Inserting records with non-existent references.
- Deleting records from the parent table if they are referenced in the child table (unless cascade delete is configured).
Thus, the foreign key maintains consistency and correctness of relationships between tables.