当前位置:网站首页>How to set MySQL triggers is a simple tutorial for novices
How to set MySQL triggers is a simple tutorial for novices
2022-06-26 06:30:00 【faint trace of something】
What is a trigger ?
Triggers are database objects related to tables , Triggered when the defined conditions are met , And execute the set of statements defined in the trigger . This feature of trigger can help to ensure the integrity of data in database .
The trigger is divided into three events :INSERT( newly added )、DELETE( Delete )、UPDATE( to update ).
mysql The trigger of is equivalent to a simple stored procedure , Personally, I think it's better not to use this kind of , It would be better to write it in the program , Unless it is a large project that must be used , This kind of thing is not easy to check and migrate , But it's fast , Very convenient also ( It's contradictory. Ha ha ).

mysql
Today we will briefly talk about data synchronization between different tables in the same database INSERT New event
The following is a brief introduction. For example, a table is added with content, and another table is also generated synchronously
For example, there are two watches , The main table is qw_single, Secondary table is synchronous table qw_single_copy
We use Nacicat This software , useful , First type a database qw_single, Design table , Click to trigger function

mysql trigger

mysql trigger
name : Trigger name
Trigger :After( Let's talk about after and before The difference between :after It is to add, delete and modify data first , Trigger again , The triggered statement is later than the monitored add / delete operation , Can not affect the previous addition, deletion and modification actions ; That is to say, insert the order record first , Update the quantity of goods ;before It's to complete the trigger first , Add, delete and modify , The triggered statement precedes the monitored addition, deletion and modification , We have a chance to judge , Modify what's going to happen .)
function : With insertion , modify , Delete , We choose to insert
Then write in the following definition
begin insert into qw_single_copy (title, pid,seotitle,seokeywords,seodescription,content,logo,url,o) values( new.title, new.pid, new.seotitle, new.seokeywords,new.seodescription,new.content,new.logo,new.url,new.o); endTable fields in brackets , Isn't that easy , In this way, you only need to write data in the main table , The secondary table will be synchronized soon , This kind of writing is not commonly used by me anyway , This method is usually used Synchronization between different databases , Data table synchronization between different servers We'll talk about this next time .
边栏推荐
- The sysdig 2022 cloud native security and usage report found that more than 75% of the running containers have serious vulnerabilities
- 闭包问题C# Lua
- ByteDance starts the employee's sudden wealth plan and buys back options with a large amount of money. Some people can earn up to 175%
- Research Report on market supply and demand and strategy of China's microneedle device industry
- 同步通信和异步通信的区别以及优缺点
- Unsatisfied dependency expressed through field ‘baseMapper‘; nested exceptio
- 架构设计方法
- PyTorch混合精度原理及如何开启该方法
- 连接数服务器数据库报:错误号码2003Can‘t connect to MySQL server on ‘服务器地址‘(10061)
- Several promotion routines of data governance
猜你喜欢

Deeply uncover Ali (ant financial) technical interview process with preliminary preparation and learning direction

Gof23 - factory mode

Dpdk - tcp/udp protocol stack server implementation (II)
Customer Stories | Netease spring breeze: the "spring breeze" of the fun industry, reaching out to all areas through in-depth interaction

100 cases of go language
Installing rainbow in various kubernetes with Helm

Basic construction of SSM framework

Transaction and message semantics
![[micro service series] protocol buffer dynamic analysis](/img/86/357d55c77cc67d6413af2de59bf395.png)
[micro service series] protocol buffer dynamic analysis
New generation engineers teach you how to play with alluxio + ml (Part 1)
随机推荐
typescript的type
PyTorch混合精度原理及如何开启该方法
Go language learning notes 1.1
Ppt template crawler case
Laravel 实现 groupBy 查询分组数量
API and encapsulation of cookies
Go learning notes 1.3- data types of variables
A new paradigm for large model application: unified feature representation optimization (UFO)
01 golang and matlab code of knapsack problem
Data visualization practice: Data Visualization
Alarm operation and Maintenance Center | build an efficient and accurate alarm collaborative processing system
连接数服务器数据库报:错误号码2003Can‘t connect to MySQL server on ‘服务器地址‘(10061)
Dpdk - tcp/udp protocol stack server implementation (II)
Understanding of nil in go language
Research Report on market supply and demand and strategy of China's microneedle device industry
Experience the new features of Milvus 2.0 together
技术能力的思考和总结
低代码实时数仓构建系统的设计与实践
How to make the main thread wait for the sub thread to execute before executing
Playing RTSP streaming video on Web pages (webrtc)