你可以在 MySQL 中使用数字作为表名吗?
2021-11-20 00:00:00
mysql
我正在考虑有一个程序可以根据需要动态创建新表.我可以在 MySQL 中使用仅用数字命名的表吗?
I'm thinking of having a program that dynamically creates new tables as the need arises. Can I have tables named with just numbers in MySQL?
推荐答案
对象命名规则,包括 MySql 中的表:
Rules for naming objects, including tables in MySql:
http://dev.mysql.com/doc/refman/5.1/en/identifiers.html
标识符可以以数字开头,但除非引用可能不完全由数字.
Identifiers may begin with a digit but unless quoted may not consist solely of digits.
所以这将是无效的:
SELECT * FROM 12345;
但以下内容是有效的:
SELECT * FROM `12345`;
或者,如果在 ANSI 模式下运行,以下将起作用:
Or if running in ANSI mode the following would work:
SET @@session.sql_mode=ANSI_QUOTES;
SELECT * FROM "12345";
相关文章