Time
7 hours 36 minutes
Difficulty
Beginner
CEU/CPE
3

Video Transcription

00:00
I welcome back to Module five sequel development. We're currently in less than two foreign keys,
00:05
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
00:23
that that author I d exists
00:26
as a user, I d on the user table.
00:29
So with that said,
00:31
let's go ahead and implement that.
00:33
So I already have the articles table open
00:36
within Dee Beavers. You can always double click on the table to open up the various options.
00:41
Click on properties, go to Foreign keys, right click, Great new Foreign key
00:47
when indicate the user's table.
00:49
I want to say that the
00:52
author I d reference is the i. D column on the user's table.
00:58
Don't leave the other defaults on like okay,
01:02
and then click say
01:03
now, something to realize that's going on here is that
01:07
Steve Beaver is choosing a name
01:10
that makes sense for us. We could type any name we wanted here.
01:15
Um, But de Beber goes ahead and chooses one that makes sense. Articles, users, foreign key
01:19
and go ahead and persist.
01:26
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,
01:38
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.
01:48
But
01:49
when you're looking at diagrams like this, usually what you want to do is click on the relationship you're interested in.
01:56
Such is the one between articles and users, and that'll highlight the special relationship between those two tables.
02:02
When you're dealing with Thea those two tables
02:07
now,
02:07
something to keep in mind here is that when we look at this relationship,
02:10
we're requiring that this user exist
02:15
if it's inserted as the author, i d. For an article.
02:20
When we look at this relationship between articles and comments,
02:27
what we are indicating is that within the comment,
02:31
if a common is added, added the article, I d must exist as an idea in articles table.
02:38
And that's how all these tables are pretty much functioning
02:42
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.

Up Next

Introduction to SQL

This introductory SQL training course teaches SQL core concepts that are applied in professional environments. Once completed with the course, students 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