I welcome back to Module five sequel development. We're currently in less than two foreign keys,
and we're moving into Sub Lesson 2.6 implementation of the foreign key on the articles table. So the last foreign key that we need to add to the articles table is a reference to the user table, so that when a new article is inserted into the articles table that we are certain
that that author I d exists
as a user, I d on the user table.
let's go ahead and implement that.
So I already have the articles table open
within Dee Beavers. You can always double click on the table to open up the various options.
Click on properties, go to Foreign keys, right click, Great new Foreign key
when indicate the user's table.
I want to say that the
author I d reference is the i. D column on the user's table.
Don't leave the other defaults on like okay,
now, something to realize that's going on here is that
Steve Beaver is choosing a name
that makes sense for us. We could type any name we wanted here.
Um, But de Beber goes ahead and chooses one that makes sense. Articles, users, foreign key
and go ahead and persist.
And it's done, so we'll go back to the E R diagram. Let's go ahead and refresh. It doesn't always work. Sometimes you have to close d beaver, but sometimes it does work,
and it did. So now we can see a reference to the user table, and we can see that our four key constraints are starting to look a little bit complicated.
when you're looking at diagrams like this, usually what you want to do is click on the relationship you're interested in.
Such is the one between articles and users, and that'll highlight the special relationship between those two tables.
When you're dealing with Thea those two tables
something to keep in mind here is that when we look at this relationship,
we're requiring that this user exist
if it's inserted as the author, i d. For an article.
When we look at this relationship between articles and comments,
what we are indicating is that within the comment,
if a common is added, added the article, I d must exist as an idea in articles table.
And that's how all these tables are pretty much functioning
now. With that said, we've managed to insert the last four in key constraint that we need for this CMS database. I hope you're able to get that. Ah, users slash articles for key inserted and I will see you in the next lesson. Thank you.