5.8 Tags Foreign Keys
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
Already have an account? Sign In »
7 hours 36 minutes
I welcome back to Muzzle five sequel development. This is lesson to Thorne Keys
and we're moving into sub lesson 2.4 tags. And for the tags table, we're actually gonna have to create a pivot table. And the reason we need to great a pivot table is because tags between articles is gonna have a many too many relationship. And
what I mean is that an article
you can have many tags
and a tag
come belong to many articles.
So if something gets tagged important,
you know, you could have mark multiple articles tagged important. And then you could also have Maur tags in just that one tag
on the article as well.
So with that said, Let's get started,
We're going to Ah, right, Click on tables, Select Create New Table
and we're going to give it a name of article
We're gonna add a new column. We're gonna start with the usual I D column.
We're going to make that a big end unsigned. It's not allowed to be No.
And for this we're just gonna add the columns that we need,
which will be the article on the score i G. So that we can
and became which article it belongs to.
It's not allowed to be no,
and we need to create another new column
called Tag on a Score i d.
Same thing Big Anton signed.
It's not allowed to be No,
just looked. Okay,
let's go ahead and save what we have.
Let's add in our primary key constraint.
I'm going and save that.
Let's head back over to the columns and turn on the auto increment
And after this finishes, let's go ahead and add in the necessary foreign keys.
So we're gonna right click great new foreign key.
Let's go ahead and performing against the articles table first, so we need to select the article I d
against the reference to column I D. Which is on the articles table.
We'll select Okay,
we need to add one more foreign key,
and this time we're gonna do the tags table
column will be the tag i d.
The Russians column will be the idea on the tag stable,
and let's go ahead and save that.
It shouldn't take too long.
It seems to be taking it a little bit longer than usual.
what should be done pretty soon.
Okay, we're back. I don't know why it took it a little bit of time to perform that action. It took about a full minute to do that, but it finished.
And I bet you it looks like it already updated the E R diagram without doing a refresh, which is interesting. Usually you have to refresh or even close the application.
So within the E R diagram, we could see that the article tags table we just created sits in between the tag stable and the articles table. When a programmer or an application wants to add a tag to an article, it will first ensure that Thea tag that it's trying to add it exist.
Then it will ensure the article exists. And then it will add that as a record to the article tags table,
and that will help protect our data and integrity by assuring the tag exists and the article exists.
So that completes this lesson. Hope you were able to get those foreign keys inserted, and I'll see you in the next lesson. Thank you