2011-01-13 26 views
0

下面是創建表:使用MySQL,我試圖在一個數據庫中創建一個表,然後再插入,但我得到一個「語法」錯誤

create table lawyer_info 
(firm_name varchar(100), 
firm_url varchar(100), 
firm_address varchar(100), 
firm_city varchar(100), 
firm_state varchar(100), 
firm_zip int(5), 
firm_phone varchar(12)); 

和這裏的插件:

insert into lawyer_info ('firm_name','firm_url','firm_address','firm_city','firm_state','firm_zip','firm_phone') 
values('Leona Beane','http://www.lawyerlbeane.com/','11 Park Place, Suite 1100','New York','NY','10007','212-608-0919'), 
values('Morton S. Minsley','http://www.msmlawfirm.com/','101 Lafayette Street, 10th Floor ','New York','NY','10013','212-346-0849'), 
values('Steven K. Schwartz, P.A.,','http://www.stevenkschwartzpa.com/','20801 Biscayne Blvd','Aventura','FL','33180','305-936-8844'), 
values('Robert H. Feldman','http://www.lawyers.com/rhfeldman/','3550 North Central Avenue, Suite 1500','Phoenix','AZ','85012','602-265-1074'), 
values('Joseph M. Udall, PLC','http://www.udallattorneys.com/','18 East University, Drive,Suite 201','Mesa','AZ','85201','480-222-0398');` 

什麼我不明白就是爲什麼我得到:

#1064 - 你在你的SQL語法錯誤;檢查對應於你的MySQL服務器版本使用「」附近firm_name」,‘firm_url’,‘firm_address’,‘firm_city’,‘firm_state’,‘firm_zip’,‘firm_’在行正確的語法手冊1

回答

1

列名應加引號,或在MySQL反引號引用:

insert into lawyer_info (firm_name, firm_url, firm_address, firm_city,firm_state, firm_zip, firm_phone) 
values('Leona Beane','http://www.lawyerlbeane.com/','11 Park Place, Suite 1100','New York','NY','10007','212-608-0919'), 
values('Morton S. Minsley','http://www.msmlawfirm.com/','101 Lafayette Street, 10th Floor ','New York','NY','10013','212-346-0849'), 
values('Steven K. Schwartz, P.A.,','http://www.stevenkschwartzpa.com/','20801 Biscayne Blvd','Aventura','FL','33180','305-936-8844'), 
values('Robert H. Feldman','http://www.lawyers.com/rhfeldman/','3550 North Central Avenue, Suite 1500','Phoenix','AZ','85012','602-265-1074'), 
values('Joseph M. Udall, PLC','http://www.udallattorneys.com/','18 East University, Drive,Suite 201','Mesa','AZ','85201','480-222-0398');` 
0

你不應該引用你的屬性名稱。例如,

insert into lawyer_info (firm_name,firm_url, etc.) 
+0

是的,我是這個東西的菜鳥。謝謝。 – Adam 2011-01-13 20:30:57

0

你不應該用正常的報價,但反引號爲您科拉姆的名字......這應該是

Insert into lawyer_info (`firm_name`,`firm_url`,`firm_address`,`firm_city`,`firm_state`,`firm_zip`,`firm_phone`) 
+0

另外,你的代碼後面還有一個額外的背景,但這可能是一個stackoverflow的東西:) – Nanne 2011-01-13 20:28:11

相關問題