Can Tables in MySQL Be Named Solely with Numbers?
When considering dynamic table creation, a crucial aspect is the naming convention for these tables. In MySQL, it's important to understand the naming rules for objects, including tables.
According to MySQL's documentation, identifiers (which include table names) may begin with a digit, but they cannot consist solely of digits unless they are quoted. Therefore, a table named "12345" would be invalid without quotes.
To ensure validity, wrap the numeric table name in backticks (`) or double quotes (") if running in ANSI mode. For example:
SELECT * FROM `12345`;
Alternatively, you can enable ANSI quotes mode with the following statement:
SET @@session.sql_mode=ANSI_QUOTES; SELECT * FROM "12345";
This allows you to use double quotes as identifiers for table names, including those containing only numbers.
The above is the detailed content of Can MySQL Tables Be Named Using Only Numbers?. For more information, please follow other related articles on the PHP Chinese website!