2

I am using various websites to check my SQL syntax.
https://www.eversql.com/sql-syntax-check-validator/
https://www.piliapp.com/mysql-syntax-check/

INSERT INTO Table1 (Column1, Column2)
VALUES ('bbbbbbb', 'aaa');

INSERT INTO Table2 (Column1, Column2, Column3)
VALUES ('bbbbb', 'hhhh', 'eeee');

While the SQL works on my end, it is showing an error on the validator sites. What is the best explanation for this?

You have an error in your SQL syntax; it seems the error is around: 'INSERT `INTO Table2 (Column1, Column2, Column3) VALUES ('bbbbb', 'hhhh', 'eee' at line 5

4
  • I tested it and works.. But if you put into 2 statement in one go it could get wrong.. see this answer Commented Oct 12, 2018 at 1:23
  • Both are valid. The site is either having trouble with the semicolon or the fact there are two statements. Commented Oct 12, 2018 at 1:33
  • Your error is the ` character before the INTO keyword: INSERT INTO not INSERT `INTO Commented Oct 12, 2018 at 2:11
  • Thanks everyone. @PhamX.Bach I tried using backquotes to stop the site telling me there is an error. It didn't work, and the error message I pasted above is probably from then. It gives an error message with or without backquotes. Commented Oct 12, 2018 at 3:21

2 Answers 2

1

If I paste each INSERT statement into the eversql syntax checker one at a time, there is no error reported.

The error message you showed indicates that the parser got confused as soon as you started the second INSERT.

These two facts are a strong indicator that the syntax checker does not support checking multiple SQL statements in one go.

I assume the checker works by doing prepare() on the statement, which would check the syntax without executing the statement. Prepare does not support multi-query. This is documented: https://dev.mysql.com/doc/refman/8.0/en/c-api-multiple-queries.html

The multiple statement and result capabilities can be used only with mysql_query() or mysql_real_query(). They cannot be used with the prepared statement interface. Prepared statement handlers are defined to work only with strings that contain a single statement

Also see confirmations like this one: https://bugs.mysql.com/bug.php?id=9121

Sign up to request clarification or add additional context in comments.

Comments

0

I think that when you create tables there is an error in the type of data being used. Depending on the type of data entered, there may be a mismatch in the data type

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.