I welcome back to Module five Sequel development This is lesson to foreign keys were moving into sub. Listen to 50.5 categories and categories is going to be very similar to the way we introduced Tags.
We're also going to create a pivot table for categories,
so let's go ahead and start that process. Someone right, Click on tables, create a new table,
and we're gonna call this one art of cool
Go ahead and start adding the new columns
gonna start with the i. D column. As usual.
create another new column
article on the score. I d
Big Anton signed again. Not know. Okay,
on and of course category I d
And big and unsigned as usual. Quick. Okay,
go ahead and save what we have so far
on Dhe Rio. Let's go ahead and add the primary key constraint.
we're going to save That persists.
Let's go back to the columns to go ahead and turn on the auto increments so that the I D column takes cares of itself.
And next we just need to add the foreign keys. So right click.
It's like creating a foreign key.
Well, go ahead and start with the articles table. We're going to say that the article I d references the i d on the articles table
and leave the others default on,
and we're gonna go ahead and create another new foreign key. This time, it'll be the categories.
And we need to say that the category i d reference is the i D column on the categories table.
And we will go ahead and save that. Hopefully, this runs a little bit faster than last time.
I will go ahead and fast forward this to win. It completes.
Okay, It finished. It didn't take too long. That one was Ah, a little faster.
15 seconds, probably.
So let's go ahead and refresh this and see if we can see within the e. R. Diagram. The relationships.
Work is nicely is Oh, wait. Yes, it did
So just like we have the tags, we now have a table sitting in between the categories and the articles with foreign key constraints. These four key constraints.
What they dio again is that when somebody goes to this article categories table to indicate
is assigned to a specific article.
That article has to exist
by the idea that's being submitted to this table,
and the category has to exist by the I. D. That's being submitted to the ER
to the table as well,
and that helps protect the data and integrity of the application.
So that completes this lesson on the implementation of the article categories. Pivot table With the foreign key constraints, I hope you were able to get that implemented. And I will see you in the next lesson. Thank you.