tags:

views:

80

answers:

3

Hello,

What precautions must be taken to use Chinese characters as MySQL table names?

Thanks in advance,

John

A: 

You just need to be sure to properly escape table name anywhere using backqoutes. Besides this, it should be pretty safe to use any characters.

PS: And whenever non Chinese writing person will have to modify your code he will hate you for that.

Michal Čihař
I'm a white American who speaks zero Chinese, yet I can't imagine why I'd have a problem with it. It's not like it'd be the first time I saw a cryptic and unpronounceable table name. Except if it's in Chinese I can actually google it, so that'd be a marked improvement over most projects I've worked on.
Ken
The problem is that you can not type it and you need to copy and paste the name all the time.
Michal Čihař
+1  A: 

Although you can probably do it safely within MySQL, whether it's right or wrong the reality is that you may end up having a hard time finding support for table names with unicode characters when using third party tools. That might include back-up solutions, development languages and APIs, etc. While it's nice to try to be global thinking, in this case I would probably stick with "standard" table names.

Tom H.
+1  A: 

SQL supports delimited identifiers to allow table or column names to contain SQL keywords, whitespace, punctuation, other special characters, or international characters.

In MySQL, use back-quotes (or set the ANSI_QUOTES SQL mode to use standard double-quotes).

Example:

mysql> create table `桌子` (id serial);
mysql> show create table `桌子`\G
--------------
show create table `桌子`
--------------

*************************** 1. row ***************************
       Table: 桌子
Create Table: CREATE TABLE `桌子` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
Bill Karwin