当前位置:网站首页>MYSQL触发器要如何设置,简单教程新手一看就会
MYSQL触发器要如何设置,简单教程新手一看就会
2022-06-26 06:24:00 【一抹】
触发器是什么?
触发器是与表有关的数据库对象,在满足定义条件时触发,并执行触发器中定义的语句集合。触发器的这种特性可以协助应用在数据库端确保数据的完整性。
触发器分三个事件:INSERT(新增)、DELETE(删除)、UPDATE(更新)。
mysql的触发器相当于简单的存储过程,个人觉得这种最好是不用,写在程序里会好点,除非是大型项目一定要用到了,这种东西不好查错迁移也困难,但是它速度快,也很方便(前后矛盾了哈哈)。

mysql
今天我们就简单地讲一下同数据库不同表之间的数据同步 INSERT新增事件
下面是简单说下比如一个表里增加了内容另一个表也同步生成
比如有两个表,主表为qw_single,次表为同步表qw_single_copy
我们用到Nacicat这个软件,很好用,先打一个数据库里的qw_single,设计表,点到触发器功能

mysql触发器

mysql触发器
名字:触发器的名字
触发:After(讲一下after和before的区别:after是先完成数据的增删改,再触发,触发的语句晚于监视的增删改操作,无法影响前面的增删改动作;也就是说先插入订单记录,再更新商品的数量;before是先完成触发,再增删改,触发的语句先于监视的增删改,我们就有机会判断,修改即将发生的操作。)
功能:有插入,修改,删除,我们这次选插入
再在下面的定义里写上
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); end括号里为表字段,是不是很简单呢,这样只要在主表写入数据,次表马上就会同步,这种写法一般我反正是不常用的,一般会用这种方法的是不同的数据库之间同步,不同服务器之间的数据表同步这个我们下次再说。
边栏推荐
猜你喜欢

同步通信和异步通信的区别以及优缺点

Design and practice of low code real-time data warehouse construction system

TCP连接与断开,状态迁移图详解

技术能力的思考和总结

A tragedy triggered by "yyyy MM DD" and vigilance before New Year's Day~

成水最多的容器

技术Leader的思考技巧

【Spark】Spark SQL 字段血缘如何实现

实时数仓方案如何选型和构建

When vs code uses prettier to format JS, there is a space between the name of the function definition and the parentheses, and ESLIt does not allow this space
随机推荐
Ppt template crawler case
Thinking skills of technical leaders
Static proxy mode
100 cases of go language
MVC source code sharing
typescript的type
Connexion et déconnexion TCP, détails du diagramme de migration de l'état
Number of connections server database message: error number 2003can't connect to MySQL server on 'server address' (10061)
PyTorch使用多GPU并行训练及其原理和注意事项
Multi thread synchronous downloading of network pictures
Usage of zip (*arg)
Hot! 11 popular open source Devops tools in 2021!
Logstash - logstash sends an alarm email to email
打印数字的位信息
Basic construction of SSM framework
Playing RTSP streaming video on Web pages (webrtc)
Thread status and stop
实时数仓方案如何选型和构建
A tragedy triggered by "yyyy MM DD" and vigilance before New Year's Day~
Pychart cannot run designer Exe (this application failed to start because no Qt platform plugin could be I appears)