SQL statement DROP TRIGGER IF EXISTS sys_menu_edit; CREATE TRIGGER sys_menu_edit BEFORE UPDATE ON sys_menu FOR EACH ROW BEGIN INSERT INTO `g4m`.`sys_log` ( `table_name`, `val_id`, `data_json` ) VALUES ( 'sys_menu', old.id, CONCAT( "{", CONCAT_WS( ',', CONCAT_WS( old.id, '"id":"', '"' ), CONCAT_WS( old.CODE, '"code":"', '"' ), CONCAT_WS( old.type_dic, '"type_dic":"', '"' ), CONCAT_WS( old.NAME, '"name":"', '"' ), CONCAT_WS( old.pid, '"pid":"', '"' ), CONCAT_WS( old.status_dic, '"status_dic":"', '"' ), CONCAT_WS( old.url, '"url":"', '"' ), CONCAT_WS( old.path, '"path":"', '"' ), CONCAT_WS( old.icon, '"icon":"', '"' ), CONCAT_WS( old.sort, '"sort":"', '"' ), CONCAT_WS( old.remark, '"remark":"', '"' ), CONCAT_WS( old.create_time, '"create_time":"', '"' ), CONCAT_WS( old.modify_uer_id, '"modify_uer_id":"', '"' ), CONCAT_WS( old.modify_time, '"modify_time":"', '"' ) ), "}" ) ); MySQL uses triggers to implement logging
There are two tables in total, one is the original table news, and the other is the log table news_logs (with an additional date column), which can automatically record logs when new entries are inserted without writing code. Similarly, you can also insert update logs when updating. For details, see the MySQL documentation. mysql uses triggers to record operations MySQL cannot perform insert, update, and delete operations in one trigger. You need to create three triggers separately. Insert trigger: delimiter $$ create trigger tri_city_insert after insert on t_xfw_city for each row begin insert into t_tri_city(id,name,provinceid,ctype) values(new.id,new.name,new.provinceid,1); end Update trigger: delimiter $$ create trigger tri_city_update after update on t_xfw_city for each row begin insert into t_tri_city(id,name,provinceid,ctype) values(new.id,new.name,new.provinceid,2); end Delete trigger: delimiter $$ create trigger tri_city_delete after delete on t_xfw_city for each row begin insert into t_tri_city(id,name,provinceid,ctype) values(old.id,old.name,old.provinceid,3); end It is a bit troublesome to create three triggers for one table. I wonder if there is a better way. You may also be interested in:
|
<<: Basic ideas and codes for implementing video players in browsers
>>: javascript to switch pictures by clicking a button
Unable to load dynamic library under Linux When t...
The role of the a tag pseudo-class: ":link&qu...
1. DOCTYPE is indispensable. The browser determin...
MySQL binlog is a very important log in MySQL log...
The HTML code for intercepting text beyond multipl...
SRIOV introduction, VF pass-through configuration...
Reproduce on Kali First set suid permissions for ...
1. Before configuring the IP address, first use i...
Table of contents 1. Introduction 2. MVCC (Multi-...
Table of contents 1 Difference 1.1 Space Occupanc...
Table of contents App.vue sub1.vue sub2.vue Summa...
Preface When I was browsing Xianyu today, I notic...
The usage of H tags, especially h1, has always bee...
The core is mysqldump and Runtime The operation i...
MySQL download address: https://obs.cn-north-4.my...