Auto commit
This commit is contained in:
parent
727db1bb4a
commit
448f49d644
@ -589,5 +589,22 @@ VALUES(DEFAULT, '雷昊', 0, NOW(), 1, 1, NULL, NULL);
|
||||
创建一个触发器 `after_employee_delete`,在删除 `employee` 表数据之后,将被删除的员工信息插入到一个离职记录表 `employee_exit_log` 中,记录员工 ID、姓名、离职时间和原因(假设原因由用户输入)。
|
||||
|
||||
```sql
|
||||
CREATE TABLE employee_exit_log(
|
||||
emp_id INT,
|
||||
emp_name VARCHAR(20),
|
||||
quit_date DATE,
|
||||
quit_reason VARCHAR(50)
|
||||
);
|
||||
|
||||
DELIMITER $$
|
||||
DROP TRIGGER IF EXISTS after_employee_delete;
|
||||
CREATE TRIGGER after_employee_delete
|
||||
AFTER DELETE ON employee
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO employee_exit_log()
|
||||
VALUES(OLD.emp_id, OLD.emp_name, NOW(), NULL);
|
||||
END $$
|
||||
DELIMITER ;
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user