Learning MySQL - FOREIGN KEY CONSTRAINTS

preview_player
Показать описание
This tutorial covers what Foreign Keys are, what Constraints are, how to create foreign keys, constraints and how to implement actions based on the constraints.

MySQL Playlist:

MySQL Foreign Key Constraint Reference:

CODE SAMPLE:
ALTER TABLE characters DROP FOREIGN KEY `fk_character_race`;
DROP TABLE IF EXISTS races;
DROP TABLE IF EXISTS characters;

CREATE TABLE races (
race_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
race_name VARCHAR(30) NOT NULL
)ENGINE=INNODB;

CREATE TABLE characters(
character_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY Key,
character_name VARCHAR(50) NOT NULL,
race_id TINYINT UNSIGNED NOT NULL,
INDEX `idx_race`(race_id),
CONSTRAINT `fk_character_race`
FOREIGN KEY (race_id)
REFERENCES races(race_id) ON UPDATE CASCADE ON DELETE RESTRICT
)ENGINE=INNODB;
Рекомендации по теме
Комментарии
Автор

3 years later and its still useful, love these timeless education videos.
Thank you for putting the effort and time to make these!

Lizini
Автор

Gimli to Legolas: I never thought I’d end up in the same database as an elf!

jacksurtees
Автор

Thank you, thank you! This video helped me with several syntax errors I had. You also explained foreign key constraints in a way that finally made sense to me!

twotentsdown
Автор

I've been using MySQL for a couple of years but never created foreign keys despite the advice of fellow developers because i dont have clear understanding about it until now thank you.

ravenkavoori
Автор

Thanks a lot. I'm having trouble in creating relationships in MySQL and this really helped me.

jamesarvinrozul
Автор

5:10 is when he writes the actual query to make the link between the tables. Thanks alot for the videos, they're very high quality!

kalkalasch
Автор

Thank you Steve! You don't know how happy I am (new to MySQL) to find your video. This is really helpful. Very clear explanation on Foreign Key! I salute you!

simplejuan
Автор

Whether it's for school or work, Steve's videos will always save your ass👌

mohammedakel
Автор

Thank you Steve, keep doing what you do!!

victornwulu
Автор

Very good video! Been trying to figure out how to do this for a long time. Specifying on update and on delete helped me out very much!

ultimatebot
Автор

Thank you very much! from Buenos Aires, Argentina.

ignaciodamiang
Автор

Explained the right way, easy to follow. Great video!

niek
Автор

Your videos are so good that one like isn't enough.

elmirabelo
Автор

Very clear and understandable. Thank you

olivierkrull
Автор

you're great sir, you made me love it though i'm not a specialist, I just have a little job that is related to mysql

ZizoAhmed
Автор

Thank you so much! Great presentation and clear understanding.

jogarule
Автор

Really well done lesson! You earned a subscriber!

azuredominus
Автор

Great explanation.
Absolutely loved it ♥️

MonisKhan
Автор

Great job Man... Please could you make a video based on table with blob data type ?

chujekwu
Автор

Professor, really thank you for these tutorials.

May I ask you one thing: "when" someone may be classified as an "expert" in SQL? These tutorials, from one to ten, how much do they say about sql skills for a job?

darter