0

Can you create a table in mysql with dots (.) in it?

I´m having trouble manipulating a table with a dot in its name. I did it this way as a shortcut for a php query.

Roy_Batty
  • 135
  • 1
  • 2
  • 12
  • Does this answer your question? [Special Characters in MySQL Table Name](https://stackoverflow.com/questions/10443050/special-characters-in-mysql-table-name) – David Makogon Dec 18 '20 at 00:47

2 Answers2

4

You can create table names with punctuation by delimiting the identifiers with back-ticks.

mysql> create table `my...table` (id serial primary key);
Query OK, 0 rows affected (0.05 sec)

mysql> insert into `my...table` values (1234);
Query OK, 1 row affected (0.02 sec)

mysql> select * from `my...table`;
+------+
| id   |
+------+
| 1234 |
+------+

It's legal, but probably more trouble than it's worth. You have to remember to use the back-ticks every time you reference the table.

A good compromise is to use _ instead of a dot, because you don't have to delimit the table name for that character.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
2

You could quote the table name(s) with back-ticks — or, if you have control over it, and it's not too late, substitute the special characters with a standardized alternative:

select * from `table.name`

Permissible characters (without the need for quotes):

[0-9,a-z,A-Z$_]

Alex
  • 34,899
  • 5
  • 77
  • 90