当前位置:网站首页>[MySQL project practical optimization] complex trigger case sharing
[MySQL project practical optimization] complex trigger case sharing
2022-07-26 03:17:00 【InfoQ】
Original requirements
Demand analysis
xxMapper.update- Method call in update, Trigger aop section
- stay aop in , Go first DB The existing data of the corresponding record is obtained from the corresponding table
- Compare new 、 The value of each attribute in the old two copies of data , Record the changed data
- Data that will change , Record to the library
- Beautify the data display format , Send this data to the person in charge
Design log table
- Who did it
- Which record was moved
- Time of operation
- Changing data
- Whether this log record has been processed ( If a notice has been sent )
drop table if EXISTS mdm_basics_change_log;
create table mdm_basics_change_log(
id BIGINT PRIMARY key auto_increment COMMENT 'id',
mdm_code varchar(50) COMMENT ' Material code ',
update_by varchar(20) COMMENT ' Update person's account ',
update_name varchar(20) COMMENT ' Update the name of the person ',
update_date TIMESTAMP DEFAULT now() COMMENT ' Date of update ',
change_data LONGTEXT COMMENT ' Changed data ',
notified int default 0 COMMENT ' Has the person in charge been notified '
);
Trigger function analysis
val1 -> val2col1, col2col1, col3 Field 1_ The old value _ The new value
Field 3_ The old value _ The new value
''Trigger writing
begin endstrIFstrstrifDELIMITER //
drop TRIGGER if EXISTS trigger_recordMdmBasicsUpdate ;
CREATE TRIGGER trigger_recordMdmBasicsUpdate BEFORE UPDATE ON mdm_basics FOR EACH ROW
BEGIN
DECLARE str LONGTEXT DEFAULT '';
DECLARE split_op LONGTEXT DEFAULT ',,.';
IF old.mdm_name!=new.mdm_name THEN
set str = CONCAT_WS(split_op,' Material name ',old.mdm_name,new.mdm_name,'\n');
END IF;
IF old.mdm_note!=new.mdm_note THEN
set str = CONCAT_WS(split_op,' Material description ( chinese )',old.mdm_note,new.mdm_note,'\n');
END IF;
if str != '' and old.mdm_code != '' then
insert into mdm_basics_change_log(mdm_code,update_by,update_name,change_data) VALUES (new.mdm_code,new.update_by,new.update_name,str);
end if;
END
//
DELIMITER ;
边栏推荐
- Canvas -- draw curve -- wall clock, pie chart, five pointed star
- 论文精读-YOLOv1:You Only Look Once:Unified, Real-Time Object Detection
- Opening method of win11 microphone permission
- Dominate the salary list! What industry has a "money" path?
- GoLang日志编程系统
- Configuration and use of virtualservice, gateway and destinationrule of istio III
- STM32 - DMA notes
- ELS register window class, create window class, display window
- An article allows you to understand the relevance of cloud native containerization
- Design of golang lottery system
猜你喜欢

How to close the case prompt icon of win11? Closing method of win11 case prompt Icon

Leetcode · daily question · sword finger offer | | 115. reconstruction sequence · topological sorting

万维网、因特网和互联网的区别

Functions and usage of snownlp Library

Etcdv3 actual combat (III) -prevkv description and related operations

URDF 语法详解

Quick check of OGC WebGIS common service standards (wms/wmts/tms/wfs)

LeetCode·

The difference between the world wide web, the Internet and the Internet

js中数组排序的方法有哪些
随机推荐
离线数据仓库从0到1-阶段一资源购买配置
[untitled]
NFT因无意义而美丽
Usage of '...' in golang
了解预加载和懒加载、学会缓动动画
Continuous delivery and Devops are good friends
Win11 hide input method status bar method
一篇文章让你理解 云原生 容器化相关
Swin Transformer【Backbone】
Implement a method to find the sum of the number k and m in the array
Is the galaxy VIP account opened by qiniu safe?
GoLang 抽奖系统 设计
78. 子集
经典面试问题——OOP语言的三大特征
Use Anaconda to configure the tensorflow of GPU Version (less than 30 series graphics cards)
Hello World driver (II) - primary version
STM32 - serial port learning notes (one byte, 16 bit data, string, array)
Remember SQL optimization once
els 注册窗口类、创建窗口类、显示窗口
[NOIP2001 普及组] 最大公约数和最小公倍数问题