-
Notifications
You must be signed in to change notification settings - Fork 0
/
assertions.sql
194 lines (183 loc) · 4.32 KB
/
assertions.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#research_assistant - instructor
DELIMITER $$
CREATE TRIGGER research_assistant_trig_ins BEFORE INSERT
ON research_assistant
FOR EACH ROW
BEGIN
IF EXISTS(
SELECT *
FROM instructor
WHERE NEW.p_id = instructor.p_id
)
THEN
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'INSERT WARNING - RESEARCH ASSISTANT EXISTS IN INSTRUCTOR TABLE';
END IF;
END$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER research_assistant_trig_upd BEFORE UPDATE
ON research_assistant
FOR EACH ROW
BEGIN
IF EXISTS(
SELECT *
FROM instructor
WHERE NEW.p_id = instructor.p_id
)
THEN
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'UPDATE WARNING - RESEARCH ASSISTANT EXISTS IN INSTRUCTOR TABLE';
END IF;
END$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER instructor_ins BEFORE INSERT
ON instructor
FOR EACH ROW
BEGIN
IF EXISTS(
SELECT *
FROM research_assistant
WHERE NEW.p_id = research_assistant.p_id
)
THEN
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'INSERT WARNING - INSTRUCTOR EXISTS IN RESEARCH_ASSISTANT TABLE';
END IF;
END$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER instructor_upd BEFORE UPDATE
ON instructor
FOR EACH ROW
BEGIN
IF EXISTS(
SELECT *
FROM research_assistant
WHERE NEW.p_id = research_assistant.p_id
)
THEN
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'UPDATE WARNING - INSTRUCTOR EXISTS IN RESEARCH_ASSISTANT TABLE';
END IF;
END$$
DELIMITER ;
# mandatory - optional
DELIMITER $$
CREATE TRIGGER mandatory_ins BEFORE INSERT
ON mandatory_course
FOR EACH ROW
BEGIN
IF EXISTS(
SELECT *
FROM optional_course
WHERE NEW.c_code = optional_course.c_code
)
THEN
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'INSERT WARNING - COURSE EXISTS IN OPTIONAL COURSE TABLE';
END IF;
END$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER mandatory_upd BEFORE UPDATE
ON mandatory_course
FOR EACH ROW
BEGIN
IF EXISTS(
SELECT *
FROM optional_course
WHERE NEW.c_code = optional_course.c_code
)
THEN
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'UPDATE WARNING - COURSE EXISTS IN OPTIONAL COURSE TABLE';
END IF;
END$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER optional_ins BEFORE INSERT
ON optional_course
FOR EACH ROW
BEGIN
IF EXISTS(
SELECT *
FROM mandatory_course
WHERE NEW.c_code = mandatory_course.c_code
)
THEN
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'INSERT WARNING - COURSE EXISTS IN MANDATORY COURSE TABLE';
END IF;
END$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER optional_upd BEFORE UPDATE
ON optional_course
FOR EACH ROW
BEGIN
IF EXISTS(
SELECT *
FROM mandatory_course
WHERE NEW.c_code = mandatory_course.c_code
)
THEN
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'UPDATE WARNING - COURSE EXISTS IN MANDATORY COURSE TABLE';
END IF;
END$$
DELIMITER ;
# faculty_member - student
DELIMITER $$
CREATE TRIGGER faculty_member_ins BEFORE INSERT
ON faculty_member
FOR EACH ROW
BEGIN
IF EXISTS(
SELECT *
FROM student
WHERE NEW.p_id = student.p_id
)
THEN
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'INSERT WARNING - FACULTY MEMBER EXISTS IN STUDENT TABLE';
END IF;
END$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER faculty_member_upd BEFORE UPDATE
ON faculty_member
FOR EACH ROW
BEGIN
IF EXISTS(
SELECT *
FROM student
WHERE NEW.p_id = student.p_id
)
THEN
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'UPDATE WARNING - FACULTY MEMBER EXISTS IN STUDENT TABLE';
END IF;
END$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER student_ins BEFORE INSERT
ON student
FOR EACH ROW
BEGIN
IF EXISTS(
SELECT *
FROM faculty_member
WHERE NEW.p_id = faculty_member.p_id
)
THEN
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'INSERT WARNING - STUDENT EXISTS IN FACULTY MEMBER TABLE';
END IF;
END$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER student_upd BEFORE UPDATE
ON student
FOR EACH ROW
BEGIN
IF EXISTS(
SELECT *
FROM faculty_member
WHERE NEW.p_id = faculty_member.p_id
)
THEN
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'UPDATE WARNING - STUDENT EXISTS IN FACULTY MEMBER TABLE';
END IF;
END$$
DELIMITER ;