From the course: Learning Relational Databases
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Enforce referential integrity
From the course: Learning Relational Databases
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.