Learning MySQL - FOREIGN KEY CONSTRAINTS

Published: 02 June 2019
on channel: Steve Griffith - Prof3ssorSt3v3
44,679
697

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;


On this page of the site you can watch the video online Learning MySQL - FOREIGN KEY CONSTRAINTS with a duration of hours minute second in good quality, which was uploaded by the user Steve Griffith - Prof3ssorSt3v3 02 June 2019, share the link with friends and acquaintances, this video has already been watched 44,679 times on youtube and it was liked by 697 viewers. Enjoy your viewing!