Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are you allowed to use numbers as table names in MySQL?

Tags:

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?

like image 659
chustar Avatar asked Mar 24 '09 07:03

chustar


1 Answers

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.

So this would be invalid:

 SELECT * FROM 12345;

But the following would be valid:

 SELECT * FROM `12345`;

Or if running in ANSI mode the following would work:

SET @@session.sql_mode=ANSI_QUOTES;
SELECT * FROM "12345";
like image 112
karim79 Avatar answered Sep 30 '22 04:09

karim79