当我尝试运行此声明时:
CREATE TABLE 'score_table'
(
'name' text NOT NULL,
'email' text NOT NULL,
'company' text NOT NULL,
'score_total' bigint(11) NOT NULL,
'score_string' longtext NOT NULL,
'id' int(11) NOT NULL auto_increment,
'date' timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY ('id')
)
ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;
我收到此错误:
#1064 - You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near ''score_table'
('name' text NOT NULL, 'email' text NOT NULL, 'company' text NOT N' at line 1
我不知道什么是错的,任何帮助都会非常感激!
答案 0 :(得分:6)
表和字段名称需要用反引号而不是单引号(或根本没有引号):
CREATE TABLE `score_table`.....
答案 1 :(得分:3)
您不应将表名用这样的单引号括起来。
CREATE TABLE `score_table` (`name` text NOT NULL, `email` text NOT NULL, `company` text NOT NULL, `score_total` bigint(11) NOT NULL, `score_string` longtext NOT NULL, `id` int(11) NOT NULL auto_increment, `date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;
答案 2 :(得分:3)
使用反引号而不是单引号:
您的SQL语句应为:
CREATE TABLE score_table (
`name` text NOT NULL,
`email` text NOT NULL,
`company` text NOT NULL,
`score_total` bigint(11) NOT NULL,
`score_string` longtext NOT NULL,
`id` int(11) NOT NULL auto_increment,
`date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`))
ENGINE= MyISAM DEFAULT CHARSET=latin1;
答案 3 :(得分:2)
正如前面提到的,表名和字段名不能在引号中,所以避免它们我编辑你的查询试试这个,如果你使用魔术引号也避免使用它们(只是避免使用当前场景中的魔术引号来查找如果你这样做都是正确的。)
CREATE TABLE score_table (name text NOT NULL, email text NOT NULL, company text NOT NULL, score_total bigint(11) NOT NULL, score_string longtext NOT NULL, id int(11) NOT NULL auto_increment, date timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY (id) ) ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;