I welcome back to Marshall five Sequel Development This is lesson to foreign keys, and we are moving into the first sub lesson 2.2
implementation of the foreign key on the images table.
The images table is a good place to start. It's gonna It's a fairly simple table with only one foreign key,
and that is the article i d.
To recap A foreign key is a primary key in another table.
So we're gonna add in a constraint that when a record is added to the images table, the Article I d. Must exist.
So if somebody attempts to add a image that belongs to Article I 82
the database is going to ensure that there is a record on the articles table that has the idea of two.
it is not possible for the database to accept a record into the images table where the article I D does not exist in the articles table, as that won't make sense in the context of our application.
Now let's go ahead and get started with implementing that.
So if we go to the properties tab when we go to the floor in Keys section, Let me right click And we say we indicate to select or create new foreign key
and we're gonna select articles as our reference table.
The column we're going to make related to the reference table is the article I d column.
And that's gonna be the i. D. Column on the articles table.
We're gonna leave the other options as
as defaults and we're going to click, okay?
And we're going to go ahead and click Save
Where's the code that will generate the flooring key? Of course, we could go and run this code ourselves, but
de Beber showing me the code and I'm gonna go ahead and click Persists and De Beber will run. That code
should take But a moment now If we closed the images
table, then we double click on it again to reopen it
and go to the E R diagram.
If we can see that we now have
we now have the images
table bound to the articles tail
with respect to article underscore I D and I d.
So that completes this lesson. I hope you were able to get that for key implemented, and I will see you in the next lesson. Thank you.