当前位置:网站首页>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 .
边栏推荐
- PyTorch混合精度原理及如何开启该方法
- LightGBM--调参笔记
- Number of connections server database message: error number 2003can't connect to MySQL server on 'server address' (10061)
- Playing RTSP streaming video on Web pages (webrtc)
- Custom reference formats used by Zotero
- Jasminum plug-in of Zotero document management tool
- TCP連接與斷開,狀態遷移圖詳解
- 自顶向下的变成方法
- 宝塔服务器搭建及数据库远程连接
- Research Report on pallet handling equipment industry - market status analysis and development prospect forecast
猜你喜欢

Import / export function implementation

Thinking skills of technical leaders

DPDK——TCP/UDP协议栈服务端实现(二)

Jasminum plug-in of Zotero document management tool

直播预告丨消防安全讲师培训“云课堂”即将开讲!

事务与消息语义

消息队列-功能、性能、运维对比

Message queue - function, performance, operation and maintenance comparison

TCP連接與斷開,狀態遷移圖詳解

Efk Upgrade to clickhouse log Storage Reality
随机推荐
Basic construction of SSM framework
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
【微服务系列】Protocol buffer动态解析
API and encapsulation of cookies
Ppt template crawler case
Mongodb -- use mongodb to intercept the string content in the field and perform grouping statistics
Web components series (10) -- realize the basic layout of mycard
Library management system
A tragedy triggered by "yyyy MM DD" and vigilance before New Year's Day~
How to select and build a real-time data warehouse scheme
C# Nuget离线缓存包安装
Gof23 - builder mode
Go语言学习笔记 1.2-变量篇
【Spark】Spark SQL 字段血缘如何实现
Logstash - logstash pushes data to redis
Understanding of nil in go language
GoF23—建造者模式
Self attention and multi head self attention (MSA) in transformer
LightGBM--调参笔记
Dpdk - tcp/udp protocol stack server implementation (I)