Auto commit
This commit is contained in:
parent
37f68f467b
commit
983e28df10
@ -338,6 +338,22 @@ WHERE dept_id = 1;
|
||||
|
||||
创建一个触发器 `after_job_update`,在更新 `job` 表的 `min_salary` 或 `max_salary` 字段后,自动调整 `employee` 表中相关员工的工资,使其符合新的工资范围。
|
||||
|
||||
```sql
|
||||
DELIMITER $$
|
||||
DROP TRIGGER IF EXISTS after_job_update;
|
||||
CREATE TRIGGER after_job_update
|
||||
AFTER UPDATE ON job
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE employee
|
||||
SET salary = IF(salary > NEW.max_salary, NEW.max_salary, IF(salary < NEW.min_salary, min_salary, salary))
|
||||
WHERE job_id = NEW.job_id;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 练习题 10: 记录部门变更
|
||||
|
||||
创建一个触发器 `after_employee_update`,在更新 `employee` 表的 `dept_id` 字段后,将变更记录插入到一个新的日志表 `department_change_log` 中,记录员工 ID、旧部门 ID、新部门 ID 和变更时间。
|
||||
|
Loading…
x
Reference in New Issue
Block a user