Search code examples
mysqlsqldatabase-trigger

SQL Trigger (as) is not a valid input at this position error - MySQL


I am not sure why I am keep getting

the error on line number 3. (as) is not a valid input at this position?

CREATE TRIGGER PendingPublish 
AFTER INSERT ON TopicPending
    AS
BEGIN
IF NEW.TopicApproved = 'YES' THEN
INSERT INTO Topics (Title,Description,Question1,Qustion2,Question3,Question4,UserID)
VALUES (NEW.Title,NEW.Description,NEW.Question1,NEW.Question2,NEW.Question3,NEW.Question4,NEW.UserID);
END IF;
END

Solution

  • You have to add DELIMITER:

    Try this.

    DELIMITER $$
    CREATE TRIGGER PendingPublish 
    AFTER INSERT ON TopicPending
    FOR EACH ROW
    BEGIN
        IF NEW.TopicApproved = 'YES' THEN
        INSERT INTO Topics (Title,Description,Question1,Qustion2,Question3,Question4,UserID)
        VALUES (NEW.Title,NEW.Description,NEW.Question1,NEW.Question2,NEW.Question3,NEW.Question4,NEW.UserID);
    END IF;
    END$$
    DELIMITER ;