Created
June 8, 2020 14:18
-
-
Save JohnRoux/7603baa069130697cf4574e9f2fd1480 to your computer and use it in GitHub Desktop.
Dependant Courses example sql db
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE SCHEMA IF NOT EXISTS `varsity`; | |
CREATE TABLE `varsity`.`courses` ( | |
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, | |
`name` VARCHAR(45) NULL, | |
PRIMARY KEY (`id`)); | |
CREATE TABLE `varsity`.`prerequisites` ( | |
`parent_course_id` BIGINT UNSIGNED NOT NULL, | |
`child_course_id` BIGINT UNSIGNED NOT NULL, | |
PRIMARY KEY (`parent_course_id`, `child_course_id`), | |
FOREIGN KEY (`parent_course_id`) REFERENCES courses(`id`), | |
FOREIGN KEY (`child_course_id`) REFERENCES courses(`id`), | |
UNIQUE `unique_index`(`parent_course_id`, `child_course_id`) | |
); | |
INSERT INTO `varsity`.`courses` (`name`) VALUES | |
("John's Intro to SQL"), | |
("John's Secondary SQL Course"), | |
("John's MySQL Course"), | |
("John's Advanced MySQL Course"); | |
INSERT INTO `varsity`.`prerequisites` (`parent_course_id`, `child_course_id`) VALUES | |
(2, 1), | |
(3, 1), | |
(4, 1), | |
(4, 2), | |
(4, 3) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment