首页 新闻 会员 周边 捐助

MySQL如何利用触发器于联立的两表自动插入数据

0
悬赏园豆:50 [已关闭问题] 关闭于 2019-12-20 22:00

同一个数据库下的gorder表与goods表,我想给gorder表中的字段Money自动触发插入数据为goods表中的Price与gorder表Cust_Count的乘积

代码如下

CREATE TRIGGER tri_1 AFTER UPDATE ON gorder FOR EACH ROW BEGIN
IF (gorder.Cust_Count!=NULL)AND(gorder.Cust_Count!=0)
THEN
UPDATE gorder
SET gorder.Money=goods.Price*gorder.Cust_Count
WHERE (id=gorder.Money) AND (goods.Gid=gorder.Gid);
ELSE SELECT E001 INTO gorder;
ELSE IF;
END;

错误提示如下
Query : CREATE TRIGGER tri_1 AFTER Update ON gorder FOR EACH ROW BEGIN if (gorder.Cust_Count!=null)and(gorder.Cust_Count!=0) then update...
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6
Execution Time : 00:00:00:000
Transfer Time : 00:00:00:000
Total Time : 00:00:00:000

Query : else SELECT E001 INTO gorder
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'else SELECT E001 INTO gorder' at line 1
Execution Time : 00:00:00:000
Transfer Time : 00:00:00:000
Total Time : 00:00:00:000

Query : else if
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'else if' at line 1
Execution Time : 00:00:00:000
Transfer Time : 00:00:00:000
Total Time : 00:00:00:000

Query : END
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END' at line 1
Execution Time : 00:00:00:000
Transfer Time : 00:00:00:000
Total Time : 00:00:00:000

求助!!!

寂子的主页 寂子 | 菜鸟二级 | 园豆:202
提问于:2019-12-20 21:18
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册