Auto commit
This commit is contained in:
parent
ce0f22d5f5
commit
a3837c3a77
@ -455,6 +455,22 @@ DELIMITER ;
|
||||
|
||||
创建一个触发器 `before_employee_insert`,在插入 `employee` 表数据时,如果工资低于职位的最低工资,则自动将其调整为最低工资。
|
||||
|
||||
```sql
|
||||
DELIMITER $$
|
||||
DROP TRIGGER IF EXISTS before_employee_insert;
|
||||
CREATE TRIGGER before_employee_insert
|
||||
BEFORE INSERT ON employee
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
IF NEW.salary < (SELECT min_salary FROM job WHERE job_id = NEW.job_id ) THEN
|
||||
SET NEW.salary = min_salary;
|
||||
END IF;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 练习题 15: 记录职位变更
|
||||
|
||||
创建一个触发器 `after_employee_update`,在更新 `employee` 表的 `job_id` 字段后,将变更记录插入到一个新的日志表 `job_change_log` 中,记录员工 ID、旧职位 ID、新职位 ID 和变更时间。
|
||||
|
Loading…
x
Reference in New Issue
Block a user