很抱歉是一个痛苦,但MySQL 5.1.36中的另一个1064错误

时间:2011-01-13 21:40:30

标签: mysql insert

错误消息:

1064 - 您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以便在'values('name','url','address','city','state','zip','phone')附近使用正确的语法,值('name','url'在第3行

创建表格:

create table lawyer_info
(firm_name varchar(100) not null,
firm_url varchar(100) not null,
firm_address varchar(100) not null,
firm_city varchar(100) not null,
firm_state varchar(100) not null,
firm_zip varchar(12) not null,
firm_phone varchar(15) not null);

数据:

insert into lawyer_info firm_name,firm_url,firm_address,firm_city,firm_state,firm_zip,firm_phone)
values('name','url','address','city','state','zip','phone'),
values('name','url','address','city','state','zip','phone'),
values('name','url','address','city','state','zip','phone'),
values('name','url','address','city','state','zip','phone'),
values('name','url','address','city','state','zip','phone'),
values('name','url','address','city','state','zip','phone'),
values('name','url','address','city','state','zip','phone');

3 个答案:

答案 0 :(得分:8)

MySQL的批量插入语法每次都不需要VALUES:

INSERT INTO lawyer_info 
  (firm_name,firm_url,firm_address,firm_city,firm_state,firm_zip,firm_phone)
VALUES ('name','url','address','city','state','zip','phone'),
       ('name','url','address','city','state','zip','phone'),
       ('name','url','address','city','state','zip','phone'),
       ('name','url','address','city','state','zip','phone'),
       ('name','url','address','city','state','zip','phone'),
       ('name','url','address','city','state','zip','phone'),
       ('name','url','address','city','state','zip','phone');

答案 1 :(得分:4)

您忘记将列列表包装(并且如前所述,删除不必要的值关键字。 试试这个:

insert into lawyer_info (firm_name,firm_url,firm_address,firm_city,firm_state,firm_zip,firm_phone) 
values('name','url','address','city','state','zip','phone'), 
('name','url','address','city','state','zip','phone'), 
('name','url','address','city','state','zip','phone'),
('name','url','address','city','state','zip','phone'), 
('name','url','address','city','state','zip','phone'), 
('name','url','address','city','state','zip','phone'), 
('name','url','address','city','state','zip','phone'); 

答案 2 :(得分:0)

您无需为列命名。只是:

insert into lawyer_info
values('name','url','address','city','state','zip','phone'),
      ('name','url','address','city','state','zip','phone');