PiraTa
PiraTa

Reputation: 485

MYSQL trigger syntax error. #1064

delimiter //
CREATE TRIGGER Raiting_added AFTER INSERT ON raiting
FOR EACH ROW
BEGIN

declare del INT;
SET del = (SELECT COUNT( rait_id ) FROM  `raiting` WHERE NEW.movie_id AND user = NEW.user);

IF del > 0 THEN
DELETE FROM movies WHERE movie_id = NEW.movie_id AND user = NEW.user
END IF;

UPDATE movies
SET raiting = ( SELECT ROUND( AVG( seted_rait ) , 1 )
FROM  `raiting` 
WHERE movie_id = NEW.movie_id)
WHERE movie_id = NEW.movie_id
END
delimiter;

Error : #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END IF; UPDATE movies SET raiting = ( SELECT ROUND( AVG( seted_rait ) , 1 ) ' at line 10

what is problem? can someone help?

Upvotes: 0

Views: 122

Answers (1)

ôkio
ôkio

Reputation: 1790

You have forgotten "= movie_id" and few semicolons

delimiter //
CREATE TRIGGER Raiting_added AFTER INSERT ON raiting
FOR EACH ROW
BEGIN

declare del INT;
SET del = (SELECT COUNT( rait_id ) FROM  `raiting` WHERE NEW.movie_id AND user = NEW.user);

IF del > 0 THEN
DELETE FROM movies WHERE movie_id = NEW.movie_id AND user = NEW.user;
END IF;

UPDATE movies
SET raiting = ( SELECT ROUND( AVG( seted_rait ) , 1 )
FROM  `raiting` 
WHERE movie_id = NEW.movie_id)
WHERE movie_id = NEW.movie_id;
END;
//
delimiter ;

Upvotes: 0

Related Questions