Home > Database > Mysql Tutorial > Can MySQL Table Names Be Just Numbers?

Can MySQL Table Names Be Just Numbers?

Patricia Arquette
Release: 2024-12-24 09:31:18
Original
767 people have browsed it

Can MySQL Table Names Be Just Numbers?

Table Naming in MySQL: Can Numbers Be Used?

It is often necessary to dynamically create new tables in MySQL. A question that arises is whether it is permissible to use tables named solely with numbers.

Rules for Table Naming in MySQL

According to MySQL documentation, identifiers like table names have specific naming rules:

  • Identifiers can start with a digit.
  • However, they cannot consist entirely of digits unless they are quoted.

Implications for Using Numbers as Table Names

These rules imply the following:

  • Invalid: SELECT * FROM 12345; (table name is not quoted)
  • Valid: SELECT * FROM 12345; (table name is quoted)

ANSI Mode Alternative

In ANSI mode, the following syntax is also valid for unquoted number-only table names:

  • SET @@session.sql_mode=ANSI_QUOTES;
  • SELECT * FROM "12345";

Conclusion

As long as proper quoting is used or ANSI mode is enabled, it is permissible to have number-only table names in MySQL, providing flexibility for dynamic table creation.

The above is the detailed content of Can MySQL Table Names Be Just 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