-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFINAL.sql
146 lines (128 loc) · 4.77 KB
/
FINAL.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
-- -----------------------------------------------------
-- Schema studGrade
-- -----------------------------------------------------
USE `mydb` ;
-- -----------------------------------------------------
-- Table `mydb`.`department`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`department` (
`id` INT NOT NULL AUTO_INCREMENT,
`department_name` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`user_type`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`user_type` (
`id` INT NOT NULL AUTO_INCREMENT,
`user_type_name` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`subject`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`subject` (
`id` INT NOT NULL AUTO_INCREMENT,
`subject_code` VARCHAR(45) NOT NULL,
`subject_name` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`users` (
`id` INT NOT NULL AUTO_INCREMENT,
`first_name` VARCHAR(45) NOT NULL,
`last_name` VARCHAR(45) NOT NULL,
`birthday` DATE NOT NULL,
`contact` INT NOT NULL,
`address` VARCHAR(45) NOT NULL,
`dept_id` INT NOT NULL,
`user_type` INT NOT NULL,
`password_log` VARCHAR(45) NOT NULL,
`gender` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id`),
INDEX `dept_idFK_idx` (`dept_id` ASC) VISIBLE,
INDEX `user_typeFK_idx` (`user_type` ASC) VISIBLE,
CONSTRAINT `user_typeFK`
FOREIGN KEY (`user_type`)
REFERENCES `mydb`.`user_type` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `dept_idFK`
FOREIGN KEY (`dept_id`)
REFERENCES `mydb`.`department` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`subject_handled_by`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`subject_handled_by` (
`id` INT NOT NULL AUTO_INCREMENT,
`user_id` INT NOT NULL,
`subject_id` INT NOT NULL,
`sched_time_date` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id`),
INDEX `subj_idFK_idx` (`subject_id` ASC) VISIBLE,
INDEX `usr_idFK_idx` (`user_id` ASC) VISIBLE,
CONSTRAINT `subj_idFK`
FOREIGN KEY (`subject_id`)
REFERENCES `mydb`.`subject` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `usr_idFK`
FOREIGN KEY (`user_id`)
REFERENCES `mydb`.`users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`grade_category`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`grade_category` (
`grade_category_id` INT NOT NULL AUTO_INCREMENT,
`category_name` VARCHAR(45) NOT NULL,
PRIMARY KEY (`grade_category_id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`grade`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`grade` (
`gradeID` INT NOT NULL AUTO_INCREMENT,
`student_id` INT NOT NULL,
`grade_category` INT NOT NULL,
`subject_handle_id` INT NOT NULL,
PRIMARY KEY (`gradeID`),
INDEX `gradeCategoryFK_idx` (`grade_category` ASC) VISIBLE,
INDEX `gradeFK_idx` (`subject_handle_id` ASC) VISIBLE,
CONSTRAINT `gradeFK`
FOREIGN KEY (`subject_handle_id`)
REFERENCES `mydb`.`subject_handled_by` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `gradeCategoryFK`
FOREIGN KEY (`grade_category`)
REFERENCES `mydb`.`grade_category` (`grade_category_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `stud_idFK`
FOREIGN KEY (`student_id`)
REFERENCES `mydb`.`users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;