Lab 7
EX1
Create a trigger that, when a new department is inserted into the department table, automatically assigns a temporary manager to that department in the management table.
DELIMITER//
CREATE TRIGGER ex1
AFTER INSERT ON department
FOR EACH ROW
BEGIN
-- 随机选取一个manager
DECLARE new_head INT;
SET new_head = (SELECT head_ID FROM head ORDER BY RAND() LIMIT 1);
INSERT INTO management VALUES(new.Department_ID, new_head, 'Yes');
END//
DELIMITER;
INSERT INTO department VALUES(16, 'Test name', 2023, 16, 0, 0