From the course: Programming Foundations: Databases

Unlock the full course today

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

Relationship rules and referential integrity

Relationship rules and referential integrity

From the course: Programming Foundations: Databases

Start my 1-month free trial

Relationship rules and referential integrity

- Once we've decided what our relationships will be, what they represent, and how they connect data, it's time to decide whether to enforce them. Databases allow us to benefit from referential integrity, which means the database will be aware of the relationship and will not let you or another user modify data in a way that violates that relationship. This helps us to maintain the consistency of the database. Let's look again at our Customers table and our Dishes table. The Customers FavoriteDish column is a foreign key from the Dishes table. It's really just a number, but we can tell the database when we create this table, that the number in this field also needs to exist in a field in the other table. It wouldn't make sense to set a customer's favorite dish to something that doesn't exist. So if we entered a customer or updated their record and tried to put in something that doesn't exist, the database would reject…

Contents