SQLite 触发器AFTER DELETE

SQLite 触发器AFTER DELETE

它指定了在删除数据后如何创建触发器。我们有两个表:COMPANY和AUDIT。

COMPANY表:

CREATE TABLE COMPANY(
   ID INT PRIMARY KEY     NOT NULL,
   NAME           TEXT    NOT NULL,
   AGE            INT     NOT NULL,
   ADDRESS        CHAR(50),
   SALARY         REAL
);

追踪表:

CREATE TABLE AUDIT(
    EMP_ID INT NOT NULL,
    ENTRY_DATE TEXT NOT NULL
); 

创建触发器after delete:

使用以下语法在删除操作后在COMPANY表上创建名为“after_del”的触发器。

CREATE TRIGGER after_del  AFTER DELETE  
ON COMPANY
BEGIN
INSERT INTO AUDIT(EMP_ID, ENTRY_DATE) VALUES (new.ID, datetime('now'));
END;

SQLite 触发器AFTER DELETE

现在从旧表中删除记录:

DELETE FROM COMPANY;

SQLite 触发器AFTER DELETE

查看触发器:

SELECT name FROM sqlite_master
WHERE type = 'trigger'; 

输出:

SQLite 触发器AFTER DELETE

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程