phpmyadmin mysql触发语法错误 [英] phpmyadmin mysql trigger syntax error

查看:139
本文介绍了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

推荐答案

要纠正的错误很多.

  1. 没有结束语.
  2. 不遵循语法顺序.
  3. 变量声明不正确.
  4. 从列中选择变量不正确.
  5. 不支持基于括号的时钟.
  6. inserted仅包含一行吗?否则,您需要where子句或limit.
  1. No end of statements.
  2. No order of syntax followed.
  3. Declaration of variables is not correct.
  4. Selection in to variables from a column is not correct.
  5. Brace based clocks is not supported.
  6. Does table inserted contain only one row? Otherwise you need a where clause or limit.
  7. 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触发语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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