Auto commit
This commit is contained in:
parent
37fccb1898
commit
ce0f22d5f5
@ -434,6 +434,23 @@ DELIMITER ;
|
|||||||
|
|
||||||
创建一个触发器 `before_department_update`,在更新 `department` 表数据时,防止修改 `location` 字段。如果尝试修改,抛出错误。
|
创建一个触发器 `before_department_update`,在更新 `department` 表数据时,防止修改 `location` 字段。如果尝试修改,抛出错误。
|
||||||
|
|
||||||
|
```sql
|
||||||
|
DELIMITER $$
|
||||||
|
DROP TRIGGER IF EXISTS before_department_update;
|
||||||
|
CREATE TRIGGER before_department_update
|
||||||
|
BEFORE UPDATE ON department
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
IF NEW.location <> OLD.location THEN
|
||||||
|
SIGNAL SQLSTATE '45000'
|
||||||
|
SET MESSAGE_TEXT = '无法更新部分的位置';
|
||||||
|
END IF;
|
||||||
|
END $$
|
||||||
|
DELIMITER ;
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#### 练习题 14: 自动调整工资
|
#### 练习题 14: 自动调整工资
|
||||||
|
|
||||||
创建一个触发器 `before_employee_insert`,在插入 `employee` 表数据时,如果工资低于职位的最低工资,则自动将其调整为最低工资。
|
创建一个触发器 `before_employee_insert`,在插入 `employee` 表数据时,如果工资低于职位的最低工资,则自动将其调整为最低工资。
|
||||||
|
Loading…
x
Reference in New Issue
Block a user