Create a foreign key in phpmyadmin and relate to primary key

preview_player
Показать описание
Primary keys and foreign keys and how they relate together is the crux of how relational databases work. in this video I add a foreign key to the students table named course_fk. I index field and then through the relation view I relate this field to the primary key field course_id in the courses table.
Through the video I highlight how relationships work and how the constraints that are part of relationships in a relational database force the integrity of data by ensuring values in the foreign key must relate to valid IDs in the primary key it is related to.
Рекомендации по теме
Комментарии
Автор

Much love from Jamaica. It's amazing how this video is 4+ years old and it helped perfectly.

hackerprime
Автор

Thanks for saving my project! very clear tutorial and great voice too 🔥

touka
Автор

If you have error #1452 go-to 4:08.
Wonderful explanation of why this error occurs. Thank you, I just realized where was my problem whole this time spent on google looking for the solution to my problem.

xoxoo
Автор

Nice and clear. Ah, so rare. Thanks so much!

aldangelo
Автор

Thanks ob wex! Great job, well explained. Was hung up with the generic error & at 4' video mark you solved my problem. I hadn't setup the foreign key default value correctly, so now I see obvious matching problems with the reference key. I corrected by setting a default value. TU

BriO
Автор

this video just saved my job and life.

THEJOENATOR
Автор

So what Restrict and Cascade mean : First thing to know is, Google Definition : The table containing the foreign key is called the child table, and the table containing the candidate key is called the referenced or parent table.
Here Foreign key is set as child of a Parent table,
Restrict on delete : it mean that you are restricted to delete a row in parent row ( record ) that is a reference of a foreign key.
Cascade on update: if a parent record ( reference column ) is updated, cascade will auto update the child row as well.

GohersWay
Автор

Didn't know you had to index! Thanks! :)

LightningFox
Автор

Very very helpful video!!!
Setting the database type to innoDB first may be worth a mention too.

FlightSimMuseum
Автор

Really need this to my transaction system

tanny_edits
Автор

thank you so much. god bless you bro. it helped me so much . thanks

doublet
Автор

Thank you very much, your videos have been very helpful to me!

alisona
Автор

Great video! I was able to understand the foreign key constraint setting better. However, your mention of one to many relationship between the course and student tables is not correct. It is actually a many to many relationship: each student can register for many courses and each course have can many students. That's why you'd need an intersection table (i.e. enrollment) to eliminate that many to many relationship. Thanks for the video.

dembasissoko
Автор

It's a great help, sir. Jazakallahu khair :)

abdullahal-sakif
Автор

So if the student has multiple courses you have to make a table for each course??

vaticinus
Автор

Is it possible to insert into a table with a foreign key without inserting anything into the table with primary key/child table?

hackerprime
Автор

i dont have the index as a drop down or relation view? is my php old version or yours?

rw
Автор

good! there is any video that explain many to many relationship?

sss-ksyk
Автор

thank you, i appreciate a lot. Subscribed

ramaken
Автор

great little video. Do you have one in your list to display the related data via PHP

Jonathan-mkju