Mysql error due to reserve words in query.

Posted on October 18, 2016 by Suresh Kamrushi in Mysql

Sometime it happens, you create field name or table name with reserve keywords in mysql. And than try to run query using that keyword, you will get some SQL syntax error like below:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near..."

Keywords are words that have significance in SQL. Certain keywords, such as SELECT, DELETE, or BIGINT, are reserved and require special treatment for use as identifiers such as table and column names. This may also be true for the names of built-in functions.

Nonreserved keywords are permitted as identifiers without quoting.

mysql> CREATE TABLE interval (begin INT, end INT);

BEGIN and END are keywords but not reserved, so their use as identifiers does not require quoting. INTERVAL is a reserved keyword and must be quoted to be used as an identifier:

mysql> CREATE TABLE `interval` (begin INT, end INT);

Here is the complete list of reserved keywords in Mysql: MySql 5.7 Keywords


Tagged as , ,