Time
7 hours 36 minutes
Difficulty
Beginner
CEU/CPE
3

Video Transcription

00:00
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
00:09
implementation of the foreign key on the images table.
00:13
The images table is a good place to start. It's gonna It's a fairly simple table with only one foreign key,
00:18
and that is the article i d.
00:20
To recap A foreign key is a primary key in another table.
00:25
So we're gonna add in a constraint that when a record is added to the images table, the Article I d. Must exist.
00:33
So if somebody attempts to add a image that belongs to Article I 82
00:39
the database is going to ensure that there is a record on the articles table that has the idea of two.
00:45
That way,
00:47
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.
00:58
Now let's go ahead and get started with implementing that.
01:03
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
01:14
and we're gonna select articles as our reference table.
01:17
The column we're going to make related to the reference table is the article I d column.
01:22
And that's gonna be the i. D. Column on the articles table.
01:26
We're gonna leave the other options as
01:29
as defaults and we're going to click, okay?
01:36
And we're going to go ahead and click Save
01:38
Where's the code that will generate the flooring key? Of course, we could go and run this code ourselves, but
01:46
de Beber showing me the code and I'm gonna go ahead and click Persists and De Beber will run. That code
01:55
should take But a moment now If we closed the images
01:59
table, then we double click on it again to reopen it
02:02
and go to the E R diagram.
02:07
If we can see that we now have
02:09
the
02:12
we now have the images
02:14
table bound to the articles tail
02:16
with respect to article underscore I D and I d.
02:21
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.

Up Next

Introduction to SQL

This introductory SQL training teaches SQL core concepts that can be applied in professional environments. Once students complete this course, they will be able to query and interact with an SQL database, and know how to design database schemas.

Instructed By

Instructor Profile Image
Kitt Parker
Instructor