mysql命令有什么问题?

时间:2012-01-09 09:16:40

标签: mysql sql

当我在phpmyadmin中运行以下命令时。

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 - 密钥1的重复条目“6”

我失败了命令是对的。我不知道如何纠正它?谢谢。

3 个答案:

答案 0 :(得分: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保留字冲突,可以将列名括在反引号中。

答案 1 :(得分:2)

您不应该使用字符串作为列名。它也是ENGINE not TYPE。 它应该看起来像:

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;

答案 2 :(得分:0)

只删除列名称周围的引号,并将最后一位更改为Engine = 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;