I created a table as follows:
CREATE TABLE IF NOT EXISTS 'e!' (
`aa` int(11) unsigned NOT NULL auto_increment,
`showName` TEXT NOT NULL default '',
`startDateTime` DATETIME NOT NULL default '',
`endDateTime` DATETIME NOT NULL default '',
PRIMARY KEY (`aa`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
Then tried to insert with the query:
INSERT INTO e! (showname, startDateTime, endDateTime) VALUES('E! News ', '2012-05-03 19:00:00', '2012-05-03 20:00:00')
And it errors due to the ! in the table name, I'm assuming ! is a special character in mysql. I tried to escape it but the query still failed.
So, can I have special characters like ! or & in the table name? If yes, then I probably have to encode them somehow?
Thanks.
解决方案
Quote your ambiguous or "special" table names with a back tick:
INSERT INTO `e!` ...
Or better, don't use special characters in table names to avoid such problems.