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

Can MySQL Tables Be Named with Only Numbers?

Mary-Kate Olsen
Release: 2024-12-14 15:06:12
Original
753 people have browsed it

Can MySQL Tables Be Named with Only Numbers?

Can MySQL Tables Be Named Using Only Numbers?

While designing a program that dynamically creates tables, a common question arises: can table names consist solely of numbers in MySQL?

Table Naming Conventions in MySQL

As a relational database management system, MySQL follows specific rules for naming identifiers, including tables. According to the official documentation, an identifier may start with a digit but cannot be composed entirely of numbers.

To understand this, consider the following statement:

SELECT * FROM 12345;
Copy after login

This query is invalid because "12345" is an unquoted number.

However, there are two exceptions to this rule:

1. Quotes

Enclosing a numeric string in quotes allows it to be used as a table name:

SELECT * FROM `12345`;
Copy after login

2. ANSI Mode

If the ANSI quotes mode is enabled, the following syntax is valid:

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

In conclusion, while MySQL generally does not allow table names to consist solely of numbers, it provides two methods to override this restriction: using quotes or setting the ANSI quotes mode.

The above is the detailed content of Can MySQL Tables Be Named with 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