开发者

Sorry to be a pain, but another 1064 error in MySQL 5.1.36 [closed]

开发者 https://www.devze.com 2023-02-04 10:35 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 12 years ago.

error msg:

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 'values('name','url','address','city','state','zip','phone'), values('name','url' at line 3

create table:

create table lawyer_info
(firm_name varchar(100) not null,
firm_url varch开发者_如何学运维ar(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);

data:

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');


MySQL's bulk insert syntax doesn't require VALUES every time:

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');


You forgot to wrap your column list in ( and as already mentioned remove the unnecessary values keyword. Try this:

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'); 


you don't need to name the columns. Just:

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

精彩评论

暂无评论...
验证码 换一张
取 消