Score
0
Watch 44 Star 256 Fork 69

xuthus / 数据库SQL实战SQLMIT

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
41.构造一个触发器audit_log.md 738 Bytes
Copy Edit Web IDE Raw Blame History
xuthus authored 2019-08-12 23:23 . add:all

构造一个触发器audit_log

题目描述

构造一个触发器audit_log,在向employees_test表中插入一条数据的时候,触发插入相关的数据到audit中。

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
);

答案

create trigger audit_log
    after insert
    on employees_test
    -- for each row
begin
    insert into audit values (new.ID,new.NAME);
end;

题解

MySQL语法:

create trigger audit_log
    after insert
    on employees_test
    for each row
begin
    insert into audit values (new.ID,new.NAME);
end;

Comment ( 0 )

Sign in for post a comment