Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
试图使用phpMyAdmin创建MySQL触发器,但获取MySQL错误#1422_Mysql_Triggers - Fatal编程技术网

试图使用phpMyAdmin创建MySQL触发器,但获取MySQL错误#1422

试图使用phpMyAdmin创建MySQL触发器,但获取MySQL错误#1422,mysql,triggers,Mysql,Triggers,我试图在MySQL中创建一个触发器,该触发器在表更新后触发。 (我遇到了一个小问题,在调用我的代码之前会插入一堆行。第一个if语句正在对此进行检查。) 因此我得到了错误1422-在存储函数或触发器中不允许显式或隐式提交。 这是我的密码: DELIMITER // CREATE TRIGGER `Update_Player_Rankings` AFTER INSERT ON `sg_playerstats` FOR EACH ROW BEGIN SET

我试图在MySQL中创建一个触发器,该触发器在表更新后触发。 (我遇到了一个小问题,在调用我的代码之前会插入一堆行。第一个if语句正在对此进行检查。) 因此我得到了错误
1422-在存储函数或触发器中不允许显式或隐式提交。

这是我的密码:

DELIMITER //

CREATE TRIGGER
    `Update_Player_Rankings`
AFTER INSERT ON
    `sg_playerstats`
FOR EACH ROW

BEGIN
    SET
        @test1 = 0,
        @test2 = 0;

    SELECT
        `gameno`
    INTO
        @test1
    FROM
        `sg_gamestats`
    ORDER BY
        `gameno` DESC
    LIMIT
        0,
        1;

    SELECT
        COUNT(*)
    INTO
        @test2
    FROM
        `sg_playerstats`
    WHERE
        `gameno` = @test1
    GROUP BY
        `gameno`
    LIMIT
        0,
        1;

    IF
        @test1 = @test2
    THEN

        SET
            @var1 = 1,
            @var2 = 0;

        SELECT
            `id`
        INTO
            @var1
        FROM
            `sg_playerstats`
        ORDER BY
            `id` DESC
        LIMIT
            0,
            1;

        SELECT
            `Last Updated`
        INTO
            @var2
        FROM
            `sg_playerranking`
        LIMIT
            0,
            1;

        IF
            @var1 > @var2
        THEN

            TRUNCATE
                `sg_playerranking`;

            SET
                @Rank := 0;

            INSERT INTO
                `sg_playerranking`
            SELECT
                @Rank := @Rank + 1 AS `Rank`,
                t.*,
                @var1 AS `Last Updated`
            FROM
                (
                    SELECT
                        `player` AS `Player`,
                        SUM(1) AS `Games`,
                        SUM(`points`) AS `Points`,
                        SUM(`points`) / SUM(1) AS `Points per Game`,
                        SUM(IF(`position` = 1, 1, 0)) AS `Wins`,
                        SUM(IF(`position` = 1, 1, 0)) / SUM(1) AS` Wins per Game`,
                        SUM(IF(`position` = 1, 0, 1)) AS `Loses`,
                        SUM(IF(`position` = 1, 0, 1)) / SUM(1) AS `Loses per Game`,
                        SUM(`kills`) AS `Kills`,
                        SUM(`kills`) / SUM(1) AS `Kills per Game`,
                        SUM(`death`) AS `Deaths`,
                        SUM(`death`) / SUM(1) AS `Deaths per Game`,
                        SEC_TO_TIME(SUM(`time`) / 1000) AS `Time played`,
                        ROUND(sqrt(SUM(`points`)) + 10 * SUM(`points`) / SUM(1) + 10 * sqrt(SUM(IF(`position` = 1, 1, 0))) + 100 * SUM(IF(`position` = 1, 1, 0)) / SUM(1) - 5 * sqrt(SUM(IF(`position` = 1, 0, 1))) - 50 * SUM(IF(`position` = 1, 0, 1)) / SUM(1) + 7.5 * sqrt(SUM(`kills`)) + 75 * SUM(`kills`) / SUM(1) - 3.75 * sqrt(SUM(`death`)) - 37.5 * SUM(`death`) / SUM(1), 2) AS `Score`
                    FROM
                        `sg_playerstats`
                    GROUP BY
                        `player`
                    ORDER BY
                        `Score` DESC,
                        `Points per Game` DESC,
                        `Wins per Game` DESC,
                        `Loses per Game` ASC,
                        `Kills per Game` DESC,
                        `Deaths per Game` ASC,
                        `Points` DESC,
                        `Wins` DESC,
                        `Loses` ASC,
                        `Kills` DESC,
                        `Deaths` ASC,
                        `Games` DESC,
                        `Time played` DESC,
                        `Player` DESC
                ) t;
        END IF;
    END IF;
END;

//

DELIMITER;

我希望你能帮忙

问题在于TRUNCATE语句。无法从触发器执行该语句,因为该语句执行隐式提交。(可能还有其他原因,但这已经足够了。)

那么我该如何解决这个问题呢?我必须清理桌子才能使一切顺利!您不能使用
DELETE
语句的原因是什么?