Skip to content

Instantly share code, notes, and snippets.

@JohnRoux
Created June 8, 2020 14:18
Show Gist options
  • Save JohnRoux/7603baa069130697cf4574e9f2fd1480 to your computer and use it in GitHub Desktop.
Save JohnRoux/7603baa069130697cf4574e9f2fd1480 to your computer and use it in GitHub Desktop.
Dependant Courses example sql db
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