Junior — Middle
Explain the concept of maintaining referential integrity in a relational database.
sobes.tech AI
Answer from AI
Maintaining the integrity of related data in a relational database is achieved through integrity constraints such as primary keys (PRIMARY KEY), foreign keys (FOREIGN KEY), unique constraints, and checks (CHECK). Foreign keys ensure consistency between tables by guaranteeing that values in related columns exist in the parent table. For example, if there is an orders table and a customers table, a foreign key in orders will reference an existing customer, preventing the creation of an order for a non-existent customer. This helps prevent errors and maintain data correctness.