C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
SQLite Trigger AFTER DELETEIt specifies how to create trigger after delete the data. We have two tables COMPANY and AUDIT. COMPANY table: CREATE TABLE COMPANY( ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL ); AUDIT table: CREATE TABLE AUDIT( EMP_ID INT NOT NULL, ENTRY_DATE TEXT NOT NULL ); CREATE trigger after delete: Use the following syntax to create a trigger named "after_del" on COMPANY table after delete operation. CREATE TRIGGER after_del AFTER DELETE ON COMPANY BEGIN INSERT INTO AUDIT(EMP_ID, ENTRY_DATE) VALUES (new.ID, datetime('now')); END; Now delete the record from the old table: DELETE FROM COMPANY; See the trigger: SELECT name FROM sqlite_master WHERE type = 'trigger'; Output:
Next TopicSQLite Drop Trigger
|