From the course: Learning Relational Databases

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Enforce referential integrity

Enforce referential integrity

From the course: Learning Relational Databases

Start my 1-month free trial

Enforce referential integrity

- [Voiceover] One of the ways that we can prevent invalid entries in a child table is by placing a specific kind of data constraint on the relationship between a child table and the parent. This constraint is called referential integrity. Referential integrity ensures that related records in the child table actually point to something in the parent's table. Let's take a look at an example of how this works. Here we have our employees table and the departments table, which have a one to many relationship between them. Each employee is supposed to point to a single department, but here's the problem. Our database is currently not set up to protect us from erroneous data getting entered in the department field in the employees table. For instance, we can create a reference to a department that doesn't exist, such as if we add someone to the maintenance department. When this occurs, we have what is called an orphaned record. This means that this particular line item doesn't refer to any…

Contents