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
Data sorting asc, desc 1. Single field sorting or...
Let’s take a look first. HTML source code: XML/HT...
Table of contents Passing parameters between pare...
I am going to review Java these two days, so I wr...
Table of contents Overview How to share data betw...
Preface In web applications, in order to save tra...
1. First, use springboot to build a simple dubbo ...
As one of the most commonly used and important ut...
Table of contents The principle of Vue asynchrono...
DCL (Data Control Language): Data control languag...
Table of contents Preface application Filters Dra...
Discovering Needs If only part of an area is allo...
Preface Recently I encountered a deadlock problem...
1. Review The Buffer Pool will be initialized aft...
Create a mysql user and authorize: Format: grant ...