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?
Tables :
My trigger :
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
There are many errors to correct.
inserted
contain only one row? Otherwise you need awhere
clause orlimit
.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.