Create a foreign key in phpmyadmin and relate to primary key

Create a foreign key in phpmyadmin and relate to primary key
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.

RRelated Posts

Primary Key & Foreign Key Implementation: MySQL

http://technotip.com/2931/primary-key-foreign-key-implementation-mysql/ Implementation of Primary Key and Foreign Key, using MySQL Practical approach and the benefits of using Primary and Foreign


  • seen oOo
    good! there is any video that explain many to many relationship?
  • Dan Cacovean
    cool. tks!!!
  • Mallory M
    super helpful! thanks!
  • Mema Stamataki
    What if I want an attribute to be fk and pk at the same time? How can I do this?
  • Nick Wilson
    How come when I go to insert data into the primary key, the foreign key doesn't populate the ID?
  • Ayodeji Eniayeye
    thank you it was insightful
  • Brian Olson
    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
  • divyani chauhan
    Pls i want to the vdo for the using forenkey using the insert query. Hows that use. Pls send to me a that vdo
  • Bhimo Alkautsar
    are u irish?
  • Gohers Way
    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.
  • Sumit Ahar
    FOLLOWED THE SAME METHOD giving this error>>>>>>>>>>>>> #1452 - Cannot add or update a child row: a foreign key constraint fails (`testing`.`#sql-41c_b7`, CONSTRAINT `#sql-41c_b7_ibfk_1` FOREIGN KEY (`category_fk`) REFERENCES `category` (`cat_id`) ON UPDATE CASCADE)
  • joseph gil
    this video just saved my job and life.
  • Azmi Cole Jr
    thank you so much
  • Rama Ken
    thank you , i appreciate a lot. Subscribed
  • Eduardo V. Micami
    It worked like a charm, tyvm...
  • WORLD news
    thanks a looooooooooooot
  • Demba Sissoko
    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.
  • Jonathan Waller
    great little video. Do you have one in your list to display the related data via PHP
  • Rich Williams
    i dont have the index as a drop down or relation view? is my php old version or yours?
    you done better...
  • Amir Hazim
    Error creating foreign key on did_fk (check data types)
  • Amir Hazim
    i cant create a link to other table it says " Error creating foreign key on did_fk (check data types)"
  • Nalini pathak
    thankss...it helped me alot.
  • Zainul Abedin
    Thanks a lots
  • MD. Shafayatul Haque
    thanks a lot
  • Jobaida Jarin
    Thank you :) It helps me!
  • Abdullah Al-Sakif
    It's a great help , sir. Jazakallahu khair :)