current position:Home>How to write MySQL trigger?

How to write MySQL trigger?

2022-01-27 03:58:40 CSDN Q & A

The phenomenon and background of the problem

Write the error report according to the example in the book , But I don't understand , Will not change

mysql> CREATE TRIGGER Student_Count    -> AFTER INSERT ON Student    -> REFERENCING    -> NEW TABLE AS DELTA    -> FOR EACH STATEMENT    -> INSERT INTO StudentInsertLog(Numbers)    -> SELECT COUNT(*)FROM DELTA;
Operation results and error reporting contents

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'REFERENCING
NEW TABLE AS DELTA
FOR EACH STATEMENT
INSERT INTO StudentInsertLog(N' at line 3

What I want to achieve

Set the table every time Student The number of students added by the insertion operation of is recorded in the table StudentInsertLog in




Refer to the answer 1:

Reference resources :

CREATE OR REPLACE TRIGGER TRI_DELETE_INFO  AFTER DELETE ON T_INFO_2012  REFERENCING OLD AS OLD NEW AS NEW  FOR EACH ROWDECLARE  V_SQLERRM VARCHAR2(200);BEGIN  DELETE FROM T_INFO_2013 WHERE CODE = :OLD.CODE;  --COMMIT;  Cannot be used in trigger COMMIT;EXCEPTION  WHEN OTHERS THEN    V_SQLERRM := ' trigger  TRI_DELETE_INFO  error :' || SQLERRM;    INSERT INTO PROCEDURE_LOG      (ERRMSG, ERRDATE)    VALUES      (V_SQLERRM, SYSDATE);END;



Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270358381793.html

Random recommended