-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriggers.sql
More file actions
36 lines (33 loc) · 852 Bytes
/
triggers.sql
File metadata and controls
36 lines (33 loc) · 852 Bytes
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
CREATE TABLE STUDENT_LOGS (
message VARCHAR(100) ,
id INT AUTO_INCREMENT PRIMARY KEY
);
DELIMITER $$
CREATE TRIGGER Section_population_del BEFORE DELETE ON student_takes_section
FOR EACH ROW
BEGIN
IF EXISTS(
SELECT COUNT(*)
FROM student_takes_section
GROUP BY sec_id
HAVING COUNT(*) <= 5
)
THEN
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'Section must have at least 5 students. Cannot perform this delete command.';
END IF;
END$$
DELIMITER ;
DELIMITER //
CREATE TRIGGER log_student_ins AFTER INSERT ON STUDENT
FOR EACH ROW BEGIN
INSERT INTO student_logs (message) VALUES (" New student added.");
END;
//
DELIMITER ;
DELIMITER //
CREATE TRIGGER log_dept_ins AFTER INSERT ON dept
FOR EACH ROW BEGIN
INSERT INTO student_logs (message) VALUES ("New dept was added. Inform the department chair.");
END;
//
DELIMITER ;