From the course: Learning Relational Databases

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Solution: Establish relationships with CoderPad

Solution: Establish relationships with CoderPad

From the course: Learning Relational Databases

Solution: Establish relationships with CoderPad

(upbeat music) - [Instructor] For this challenge, we need to add in a relationship between the customers and the invoices table in the two trees database. This will help ensure that the data that we put into the database has referential integrity. For example, we're given this insert statement which will add in a row of data into the invoices table. I'm going to uncomment out this line by deleting the two hyphens and just execute it right now. Now it tells me that it's incorrect for this challenge, but the database has no problem inserting that data into the invoices table, and I can see it listed here in the result. The problem is, is that the customer's table doesn't yet have any customers in it, yet here we're referring to customer ID number one for this invoice. It doesn't actually point to any valid customer data. That's a huge problem. So to prevent this from happening, we need to put in a constraint that says that we can only enter invoices that have a valid customer ID number…

Contents