1+ -- -------------------------------------------------------------------------
2+ -- Courses table
3+ --
4+ -- @author Benjamin Russell ([email protected] )5+ -- @descrip Table for courses. These are linked to departments and quarters
6+ -- in a one quarter/department to many courses. These are also linked
7+ -- to sections in a one course to many sections fashion.
8+ -- -------------------------------------------------------------------------
9+
10+ -- TABLE CREATION ----------------------------------------------------------
11+ CREATE TABLE courses (
12+ ` id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
13+ ` quarter` SMALLINT UNSIGNED NOT NULL ,
14+ ` department` INT UNSIGNED NOT NULL ,
15+ ` course` VARCHAR (4 ) NOT NULL ,
16+ ` credits` TINYINT (2 ) UNSIGNED NOT NULL DEFAULT 0 ,
17+ ` title` VARCHAR (50 ) NOT NULL ,
18+ ` description` TEXT NOT NULL
19+ )ENGINE= InnoDb;
20+
21+ -- INDEXING ----------------------------------------------------------------
22+ ALTER TABLE ` courses`
23+ ADD CONSTRAINT UQ_courses_quarter_department_course
24+ UNIQUE (` quarter` , ` department` , ` course` );
25+
26+ -- FOREIGN KEYS ------------------------------------------------------------
27+ ALTER TABLE ` courses`
28+ ADD FOREIGN KEY FK_courses_quarter(` quarter` )
29+ REFERENCES ` quarters` (` quarter` )
30+ ON DELETE CASCADE
31+ ON UPDATE CASCADE;
32+
33+ ALTER TABLE ` courses`
34+ ADD FOREIGN KEY FK_courses_dept(` department` )
35+ REFERENCES ` departments` (` id` )
36+ ON DELETE CASCADE
37+ ON UPDATE CASCADE;
0 commit comments