Home  >  Article  >  Database  >  Why does MySQL give an error when using dashes in table names?

Why does MySQL give an error when using dashes in table names?

Barbara Streisand
Barbara StreisandOriginal
2024-11-11 14:41:02392browse

Why does MySQL give an error when using dashes in table names?

Using Dashes in MySQL Table Names

If you encounter an error like "Error Number: 1064... check the manual... near '-01-000001' at line 1," while backing up your database, it's likely due to a dash (-) in the table name. MySQL doesn't allow dashes in table names without specific handling.

To resolve this issue:

  1. Enclose the Table Name in Backticks: Surround your table name with backticks (`), which act as escape characters. For example:
SELECT * FROM `temp_01-01-000001`

By enclosing the table name in backticks, the dash symbol loses its special meaning, and MySQL treats the table name as a string.

  1. Use SQL Identifier Quoting: Alternatively, you can use SQL identifier quoting to treat the entire table name as a single quoted string. This is achieved by adding double quotes ("") around the table name, like so:
SELECT * FROM "temp_01-01-000001"

Either of these methods will allow you to query the table with a dash in its name. Remember to include the backticks or double quotes whenever you reference the table, otherwise you may still encounter errors.

The above is the detailed content of Why does MySQL give an error when using dashes in table names?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn