当前位置:网站首页>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 .
边栏推荐
- API and encapsulation of cookies
- Five solutions across domains
- 实时数仓方案如何选型和构建
- Several promotion routines of data governance
- 获取当前月份的第一天和最后一天,上个月的第一天和最后一天
- Dpdk - tcp/udp protocol stack server implementation (II)
- Go语言学习笔记 1.1
- 事务与消息语义
- Ppt template crawler case
- 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%
猜你喜欢
随机推荐
Import export simple
EFK昇級到ClickHouse的日志存儲實戰
Simple use of typescript's class interface
University Information Management System
Temperature alarm
How can an enterprise successfully complete cloud migration?
MVC source code sharing
Five solutions across domains
3.pyinstaller module introduction
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
Go language learning notes 1.1
Gof23 - prototype mode
Laravel implements groupby to query the number of packets
01 golang and matlab code of knapsack problem
Reasons why MySQL indexes are not effective
API and encapsulation of cookies
Mongodb -- use mongodb to intercept the string content in the field and perform grouping statistics
TCP连接与断开,状态迁移图详解
Install pyinstaller
TS泛型在函数、接口、类中使用介绍








