Ramesh Mudalagi
Ramesh Mudalagi

Reputation: 21

MySQL error after updating on

Here i am trying to insert into payment_table after updating the review_table only after the status in review_table is updated to 2 .But there is error after running this trigger i.e,

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the

Trigger is:

CREATE TRIGGER payment_details_trig AFTER UPDATE ON review_table
FOR EACH ROW
BEGIN
 IF NEW.status=2
  INSERT INTO payment_table(paper_id, payment_mode, payment_refNo, payment_image,status)
  VALUES (0,0,0,0,0);
 END IF;
END;

Upvotes: 1

Views: 77

Answers (2)

tpsaitwal
tpsaitwal

Reputation: 422

The issue 1064 in SQL comes in following four cases:

1) Use of reserved words:

Every version of MySQL has its own list of reserved words. These are words that are used for specific purposes or perform specific functions within the MySQL engine. If you attempt to use one of these reserved words, you will receive the 1064 error.To fix the issue, you will want to surround the word with backticks “`”.

2) Missing Data: Sometimes data in the database is missing. This can cause issues when this data is required for a query.

3) Mistyped or missing Commands: One of the most common causes for the 1064 error is when a SQL statement uses a mistyped or missing command.

4) Deprecated Commands: Some commands that were deprecated (slated for removal but still allowed for a period of time) eventually go obsolete. This means that the command is no longer valid in the SQL statement.

In your case third option is the answer is the reason of your error. You have missed writing THEN after IF.

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1269563

Nothing sticks out except for the missing THEN. You might need delimiter statements:

DELIMITER $$
CREATE TRIGGER payment_details_trig AFTER UPDATE ON review_table
    FOR EACH ROW
    BEGIN
        IF NEW.status = 2 THEN
            INSERT INTO payment_table(paper_id, payment_mode, payment_refNo, payment_image,status)
                VALUES (0, 0, 0, 0, 0);
        END IF;
    END;
$$
DELIMITER ;

Upvotes: 1

Related Questions