Home  >  Article  >  Database  >  MYSQL触发器的使用_MySQL

MYSQL触发器的使用_MySQL

WBOY
WBOYOriginal
2016-06-01 13:42:37992browse

bitsCN.com
mysql触发器格式为 create trigger trigger_name after/before  insert/update/delete on one_table for each row your_sql; 红色部分为自己命名的,蓝色部分为选择一个值,黑色部分必有,最后的绿色部分为你想出发的SQL语句; mysql中关于两个table连接操作update方法为(mysql在此处不使用join语句): update A,B set A.a2 = B.b2 where A.A1 = B.B1 and B.B2 = "XXX"其中A、B为用户所建立的表名a2、b2为表下的属性值;   mysql中使用触发器获得刚刚插入的数据关键字为NEW,即(本人对数据库的命名习惯不好): table1: records(accountid,date, month, week,income,expend ,remark); table2: Rweek( week,Wincome, Wexpend); 触发器为实现table1插入一组数据,table2针对对应的week值进行相应的汇总: create trigger t1 after insert on records for each row update Rweek set Rweek.Wincome=Rweek.Wincome+NEW.income,Rweek.Wexpend=Rweek.Wexpend+NEW.expend where Rweek.week=NEW.week;   作者 Chanthon bitsCN.com

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn