Home > Database > Mysql Tutorial > Can MySQL Tables Be Named Using Only Numbers?

Can MySQL Tables Be Named Using Only Numbers?

Mary-Kate Olsen
Release: 2024-12-20 16:56:10
Original
354 people have browsed it

Can MySQL Tables Be Named Using Only Numbers?

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`;
Copy after login

Alternatively, you can enable ANSI quotes mode with the following statement:

SET @@session.sql_mode=ANSI_QUOTES;
SELECT * FROM "12345";
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template