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

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

I am using a website check my SQL syntax: https://www.eversql.com/sql-syntax-check-validator/. While the SQL works, it is showing an error:

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

For some reason the website shows an error. Why is this happening? I've also tried this website: https://www.piliapp.com/mysql-syntax-check/

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
seedee
  • 98
  • 10
  • I tested it and works.. But if you put into 2 statement in one go it could get wrong.. see this [answer](https://stackoverflow.com/questions/3860280/sql-insert-into-multiple-tables-in-one-query) – dwir182 Oct 12 '18 at 01:23
  • Both are valid. The site is either having trouble with the semicolon or the fact there are two statements. – TomC Oct 12 '18 at 01:33
  • Your error is the `\`` character before the `INTO` keyword: `INSERT INTO` not `INSERT \`INTO` – Pham X. Bach Oct 12 '18 at 02: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. – seedee Oct 12 '18 at 03:21

2 Answers2

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

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
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