-
Notifications
You must be signed in to change notification settings - Fork 1
/
Triggers.sql
94 lines (64 loc) · 2.23 KB
/
Triggers.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
CREATE TRIGGER updateLecType
AFTER UPDATE
ON FAC_MEMBER
FOR EACH ROW
BEGIN
IF NEW.LecType IS NULL
THEN DELETE FROM RES_ASSIST WHERE RES_ASSIST.PersonID = (OLD.PersonID);
DELETE FROM ASSIST_PROF WHERE ASSIST_PROF.PersonID = (OLD.PersonID);
DELETE FROM ASSOC_PROF WHERE ASSOC_PROF.PersonID = (OLD.PersonID);
DELETE FROM PROFFESOR WHERE PROFFESOR.PersonID = (OLD.PersonID);
DELETE FROM INSTRUCTOR WHERE INSTRUCTOR.InstID = (OLD.PersonID);
END IF;
IF NEW.LecType = 1
THEN INSERT INTO RES_ASSIST (PersonID) VALUES (NEW.PersonID);
END IF;
IF NEW.LecType = 2
THEN INSERT INTO INSTRUCTOR (InstID) VALUES (NEW.PersonID);
INSERT INTO ASSIST_PROF (PersonID) VALUES (NEW.PersonID);
DELETE FROM RES_ASSIST WHERE RES_ASSIST.PersonID = (OLD.PersonID);
END IF;
IF NEW.LecType = 3
THEN INSERT INTO ASSOC_PROF (PersonID) VALUES (NEW.PersonID);
DELETE FROM ASSIST_PROF WHERE ASSIST_PROF.PersonID = (OLD.PersonID);
END IF;
IF NEW.LecType = 4
THEN INSERT INTO PROFFESOR (PersonID) VALUES (NEW.PersonID);
DELETE FROM ASSOC_PROF WHERE ASSOC_PROF.PersonID = (OLD.PersonID);
END IF;
IF NEW.LecType = 0
THEN DELETE FROM PROFFESOR WHERE PROFFESOR.PersonID = (OLD.PersonID);
END IF;
END;
-----------------------------------------------------------------------------------------
CREATE TRIGGER updateCoType
AFTER UPDATE
ON COURSE
FOR EACH ROW
BEGIN
IF NEW.CoType IS NULL
THEN DELETE FROM MANDATORY WHERE MANDATORY.CoCode = (OLD.CoCode);
DELETE FROM TECHNICAL WHERE TECHNICAL.CoCode = (OLD.CoCode);
DELETE FROM N_TECHNICAL WHERE N_TECHNICAL.CoCode = (OLD.CoCode);
DELETE FROM OPTIONAL WHERE OPTIONAL.CoCode = (OLD.CoCode);
END IF;
IF NEW.CoType = 1
THEN INSERT INTO MANDATORY (CoCode) VALUES (NEW.CoCode);
END IF;
IF NEW.CoType = 2
THEN INSERT INTO OPTIONAL (CoCode) VALUES (NEW.CoCode);
INSERT INTO TECHNICAL (CoCode) VALUES (NEW.CoCode);
END IF;
IF NEW.CoType = 3
THEN INSERT INTO OPTIONAL (CoCode) VALUES (NEW.CoCode);
INSERT INTO N_TECHNICAL (CoCode) VALUES (NEW.CoCode);
END IF;
END;
-----------------------------------------------------------------------------------------
CREATE TRIGGER deleteStudent
AFTER DELETE
ON STUDENT
FOR EACH ROW
BEGIN
DELETE FROM PERSON WHERE PERSON.PersonID = (OLD.PersonID);
END;