在MySQL中创建触发器时遇到问题 [英] Trouble in creating Trigger in MySQL

查看:47
本文介绍了在MySQL中创建触发器时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一些表的数据库.我想创建一个触发器,以使用在tblplayers中删除的记录的"pID"删除tblplayersfield中的记录"

I have a database with some tables. I want to create a trigger to 'Delete a record in tblplayersfield with "pID" of the record which was deleted in tblplayers'

CREATE TRIGGER delete_from AFTER DELETE on tblplayers
FOR EACH ROW
BEGIN
DELETE FROM tblplayerfields
    WHERE 'tblplayerfields'.'pID' = OLD.'pID';
END

推荐答案

您需要先添加定界符更改

You need to add a delimiter change first

delimiter |

CREATE TRIGGER delete_from AFTER DELETE on tblplayers
FOR EACH ROW
BEGIN
DELETE FROM tblplayerfields
    WHERE 'tblplayerfields'.'pID' = OLD.'pID';
END
|
delimiter ;

定界符向DB引擎发出语句结束的信号.通常是; .但这将在第一个; 处结束存储过程.其定义将是不完整的.

The delimiter signals the DB engine the end of your statement. Normally it is ;. But that would end the stored procedure at the first ;. And its definition would be incomplete.

您可以更改定界符并将其添加到过程的末尾.之后,将分隔符改回;

You can change the delimiter and add it to the end of your procedure. After that change the delimiter back to ;

这篇关于在MySQL中创建触发器时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆