3

I've a SQLite script which initializes a DB (SQLite 3.8.2), created as follows:

sqlite3 -init database_creation.sql sample.db

The script file is like:

 // Some `CREATE TABLE` statements

 CREATE TRIGGER update_totalprice AFTER UPDATE
   OF price, amount, boxes ON product
   BEGIN UPDATE product SET totalprice = price * boxes * amount
   WHERE idproduct = NEW.idproduct; END

 // Some `INSERT` statements.

But it generates the following error:

Error: incomplete SQL: CREATE TRIGGER update_totalprice AFTER UPDATE
   OF price, amount, boxes ON product
   BEGIN UPDATE product SET totalprice = price * boxes * amount
   WHERE idproduct = NEW.idproduct; END

// The rest of the file to the end.

I'm sure there're syntax errors nor creating the tables neither inserting the test rows, because if I comment the CREATE TRIGGER statement all works perfectly fine, and I don't find the syntax error either.

1 Answer 1

2

Ok, the problem was pretty simple. I though the "END" keyword was enough to mark the end of the CREATE TRIGGER statement (even more knowing that the UPDATE statement has already its own ';'), but after END, another ; is required:

 CREATE TRIGGER update_totalprice
 AFTER UPDATE OF price, amount, boxes ON product
 BEGIN
   UPDATE product SET totalprice = price * boxes * amount
   WHERE idproduct = NEW.idproduct;
 END;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.