phpmyadmin mysql trigger syntax error(phpmyadmin mysql 触发语法错误)
问题描述
我正在尝试编写一个 mySQL tigger,但我无法将我的代码放入 phpMyAdmin MySQL 中而不会出现语法错误.有人可以帮我吗?
i'm trying to write a mySQL tigger but i can't put my code in phpMyAdmin MySQL without getting a syntax error. can someone help me please?
表格:
我的触发器:
CREATE TRIGGER after_jeu_insert ON jeu
AFTER INSERT
AS
BEGIN
DECLARE @gameid int, @oldTurn int, @newTurn int
SELECT @gameid=idpartie FROM INSERTED
SELECT @oldturn=tour FROM partie WHERE idpartie=@gameid
IF(@oldTurn IS NULL)
{
SET @newTurn = 1
}
ELSE
{
IF(@oldTurn==1)
SET @newTurn = 2
ELSE
SET @newTurn = 1
}
UPDATE partie SET tour = @newTurn, derniercoup = NOW() WHERE idpartie = @gameid
END
我没有发现错误,如果有人可以帮助我,那就太好了.谢谢
I don't find the error, if someone could help me it would be very nice. Thanks
推荐答案
有很多错误需要更正.
- 没有结束的语句.
- 没有遵循语法顺序.
- 变量声明不正确.
- 从列中选择变量不正确.
- 不支持基于大括号的时钟.
- 表
inserted
是否只包含一行?否则你需要一个where
子句或limit
. - 等
- No end of statements.
- No order of syntax followed.
- Declaration of variables is not correct.
- Selection in to variables from a column is not correct.
- Brace based clocks is not supported.
- Does table
inserted
contain only one row? Otherwise you need awhere
clause orlimit
. - etc.
你最好多努力学习.
请参阅触发器语法和示例 以便更好地理解.
You better work more to learn.
Please refer to Trigger Syntax and Examples for better understanding.
按如下方式更改您的代码,如果您的数据库对象一切正常,它可能工作.
Change your code as follows and it may work if all is well on your database objects.
drop trigger if exists after_jeu_insert;
delimiter //
CREATE TRIGGER after_jeu_insert after insert ON jeu for each row
BEGIN
DECLARE _game_id int;
DECLARE _old_turn int;
DECLARE _new_turn int;
-- following line may not require limit clause
-- if used proper where condition.
SELECT idpartie into _game_id FROM INSERTED limit 1;
SELECT tour into _old_turn FROM partie WHERE idpartie = _game_id;
IF _old_turn IS NULL then
SET _new_turn = 1;
ELSIF _old_turn = 1 then
SET _new_turn = 2;
ELSE
SET _new_turn = 1;
END IF;
UPDATE partie
SET tour = _new_turn
, derniercoup = NOW()
WHERE idpartie = _game_id;
END;
//
delimiter;
这篇关于phpmyadmin mysql 触发语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:phpmyadmin mysql 触发语法错误


- 更改自动增量起始编号? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- SQL 临时表问题 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01