2012-01-09 81 views
1

當我在phpmyadmin中運行以下命令。mysql命令有什麼問題?

CREATE TABLE subscribers (
    'subscriber_id' int(11) NOT NULL auto_increment, 
    'customers_id' int(11) default NULL, 
    'email_address' varchar(96) NOT NULL default '', 
    'email_format' varchar(4) NOT NULL default 'TEXT', 
    PRIMARY KEY ('subscriber_id') 
) TYPE=MyISAM; 

它顯示我#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 ''subscriber_id' int(11) NOT NULL auto_increment, 'customers_id' int(11) defaul' at line 2

INSERT INTO query_builder (query_id, query_category, query_name, query_description, query_string, query_keys_list) VALUES (6, 'email,newsletters', 'All Newsletter Subscribers', 'Returns name and email address of all Customer Account subscribers and all Newsletter-Only subscribers.', 'select c.customers_firstname, c.customers_lastname, s.email_address as customers_email_address from TABLE_SUBSCRIBERS as s left join TABLE_CUSTOMERS as c on c.customers_id = s.customers_id ', '') 

它表明: 1062 - 重複條目 '6' 關鍵1

我掉下來的命令是正確的。我不知道如何糾正它?謝謝。

回答

5

您不需要列名稱附近的單引號。刪除。

這應該是

CREATE TABLE subscribers (
    subscriber_id int(11) NOT NULL auto_increment, 
    customers_id int(11) default NULL, 
    email_address varchar(96) NOT NULL default '', 
    email_format varchar(4) NOT NULL default 'TEXT', 
    PRIMARY KEY (subscriber_id) 
) TYPE=MyISAM; 

雖然,你可以,如果是與MySQL保留字相沖突的反引號括起來的列名。

+0

我刪除了單引號,它仍然顯示#1064 - 你的SQL語法錯誤;檢查與您的MySQL服務器版本相對應的手冊,以在''subscriber_id''附近使用正確的語法))TYPE = MyISAM'在第6行 – down321 2012-01-09 09:23:22

+0

@hsz:謝謝... @ down321:查看更新後的答案。我忘了從'PRIMARY KEY(subscriber_id)'中刪除單引號 – 2012-01-09 09:23:24

2

您不應該使用字符串作爲列名稱。它也是引擎不是類型。 它應該看起來像:

CREATE TABLE subscribers (
    subscriber_id int(11) NOT NULL auto_increment, 
    customers_id int(11) default NULL, 
    email_address varchar(96) NOT NULL default '', 
    email_format varchar(4) NOT NULL default 'TEXT', 
    PRIMARY KEY (subscriber_id) 
) ENGINE=MyISAM; 
0

只是去掉引號將列名,改變了最後一位發動機= MyISAM的工作對我來說:

CREATE TABLE subscribers (
    subscriber_id int(11) NOT NULL auto_increment, 
    customers_id int(11) default NULL, 
    email_address varchar(96) NOT NULL default '', 
    email_format varchar(4) NOT NULL default 'TEXT', 
    PRIMARY KEY (subscriber_id) 
) Engine=MyISAM;