2011-12-07 109 views
2

当我尝试运行此声明:CREATE TABLE 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 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

你也有你的答案 – Harsh

+1

已经给出了足够的答案,所以我想做一个评论:你真的过度使用引号。除非该名称也可以作为关键字加倍,否则不必使用它们。请参阅:http://sql-info.de/mysql/examples/CREATE-TABLE-examples.html – stackr

+0

哇!感谢所有人的回应!堆栈溢出是国王;) – bbeckford

回答

6

表名和字段名需要被放在反引号,而不是单引号(或没有引号的话):

CREATE TABLE `score_table`..... 
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 ; 
+0

这是行不通的。 – Flukey

+0

@Flukey - 修正。 – Polynomial

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; 
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 ; 
相关问题