Time
7 hours 36 minutes
Difficulty
Beginner
CEU/CPE
3

Video Transcription

00:00
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.
00:15
We're also going to create a pivot table for categories,
00:19
so let's go ahead and start that process. Someone right, Click on tables, create a new table,
00:28
and we're gonna call this one art of cool
00:31
underscore categories.
00:35
Go ahead and start adding the new columns
00:38
gonna start with the i. D column. As usual.
00:42
I don't know. Okay,
00:45
create another new column
00:48
article on the score. I d
00:55
Big Anton signed again. Not know. Okay,
01:00
on and of course category I d
01:08
not know.
01:10
And big and unsigned as usual. Quick. Okay,
01:15
go ahead and save what we have so far
01:19
on Dhe Rio. Let's go ahead and add the primary key constraint.
01:26
The I D column
01:30
we're going to save That persists.
01:34
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.
01:44
And next we just need to add the foreign keys. So right click.
01:48
It's like creating a foreign key.
01:51
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
01:59
and leave the others default on,
02:04
and we're gonna go ahead and create another new foreign key. This time, it'll be the categories.
02:10
And we need to say that the category i d reference is the i D column on the categories table.
02:16
Okay.
02:19
And we will go ahead and save that. Hopefully, this runs a little bit faster than last time.
02:25
And it's running.
02:30
I will go ahead and fast forward this to win. It completes.
02:37
Okay, It finished. It didn't take too long. That one was Ah, a little faster.
02:42
15 seconds, probably.
02:45
So let's go ahead and refresh this and see if we can see within the e. R. Diagram. The relationships.
02:53
Okay. Nope.
02:55
Work is nicely is Oh, wait. Yes, it did
03:00
and loaded it in.
03:00
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.
03:12
What they dio again is that when somebody goes to this article categories table to indicate
03:17
that a category
03:20
is assigned to a specific article.
03:23
That article has to exist
03:25
by the idea that's being submitted to this table,
03:29
and the category has to exist by the I. D. That's being submitted to the ER
03:36
to the table as well,
03:38
and that helps protect the data and integrity of the application.
03:40
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.

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