Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
293 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...