SQL235. 构造一个触发器audit_log
描述
构造一个触发器audit_log,在向employees_test表中插入一条数据的时候,触发插入相关的数据到audit中。示例1
输入:
drop table if exists audit; drop table if exists employees_test; CREATE TABLE employees_test( ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL ); CREATE TABLE audit( EMP_no INT NOT NULL, NAME TEXT NOT NULL );
输出:
1|Paul
Sqlite 解法, 执行用时: 9ms, 内存消耗: 3320KB, 提交时间: 2021-03-05
create trigger audit_log after insert on employees_test for each row begin insert into audit values(new.id,new.name); end
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3260KB, 提交时间: 2021-06-17
create trigger audit_log after insert on employees_test begin insert into audit values(new.ID, new.NAME); end;
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3292KB, 提交时间: 2021-05-29
create trigger audit_log after insert on employees_test for each row begin insert into audit values(new.id, new.name); end
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3296KB, 提交时间: 2021-05-24
create trigger audit_log after insert on employees_test begin insert into audit(emp_no,name) values(NEW.ID,NEW.NAME); end;
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3296KB, 提交时间: 2021-03-22
CREATE TRIGGER audit_log AFTER INSERT ON employees_test BEGIN INSERT INTO audit VALUES ( NEW.ID, NEW.NAME ); END