Pages

Wednesday, 10 September 2014

Do hyphens (-) in MySQL table names cause issues?

Yes, it causes issues if you use it directly like

DESCRIBE my-table;

This will definately cause issues. You will get the following error:

ERROR 1064 (42000): 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 '-table' at line 1

We can resolve this issue enclosing the tablename in backticks (`). The identifier quote character is the backtick (`). So the syntax will be

DESCRIBE `my-table`;

For more details about the permitted characters in unquoted identifiers, check the MySQL identifiers HERE.


No comments:

Post a Comment