当前位置:网站首页>[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 ;
边栏推荐
- QT笔记——临时的悬浮窗口
- URDF 语法详解
- STM32 - DMA notes
- Efficient Video Instance Segmentation via Tracklet Query and Proposal
- Continuous delivery and Devops are good friends
- 实现一个方法,找出数组中的第k大和第m大的数字相加之和
- 2022-07-21 第四小组 修身课 学习笔记(every day)
- Unknown-Aware Object Detection:Learning What You Don’t Know from Videos in the Wild(CVPR 2022)
- Why did Mr. Cao, a productionist in the field of high-end tea, choose Ruifeng L6 max?
- snownlp库各功能及用法
猜你喜欢

How to install with USB flash disk?

Opencv报错:(parameter or structure field))Unrecognized or unsupported array type in functon ‘cvGetMat‘
![[noip2001 popularization group] packing problem](/img/b7/1310b3e68d0ee016465fc069315af6.png)
[noip2001 popularization group] packing problem

Looking at the next step of BAIC bluevale through the 8billion fund-raising, product upgrading and building core capabilities are the key words

MPLS基础实验配置

线性回归原理推导

How to reinstall win7 system?

Istio三之VirtualService、Gateway、DestinationRule配置使用

记一次SQL优化

Small test (I)
随机推荐
YOLOv3: An Incremental Improvement
一篇文章让你理解 云原生 容器化相关
els 初始化窗口类
Execution process behind shell commands
Jsd-2204-cool shark Mall (Management Commodity module) -day02
ES6 set and map
Opencv saves pictures in the specified format
Managing databases in a hybrid cloud: eight key considerations
STM——EXTI外部中断学习笔记
在混合云中管理数据库:八个关键注意事项
Canvas -- draw text -- modification of pie chart
[tensorflow & pytorch] image data enhancement API
了解预加载和懒加载、学会缓动动画
hello world驱动(二)-初级版
Classic interview questions -- three characteristics of OOP language
Chen Yili, China Academy of communications technology: cost reduction and efficiency increase are the greatest value of Enterprise Cloud native applications
Leetcode · daily question · sword finger offer | | 115. reconstruction sequence · topological sorting
Small test (I)
Opencv annotates the image (picture frame + writing)
NFT因无意义而美丽