SQL插入语句出错

时间:2014-06-03 03:13:43

标签: mysql mysql-workbench

我将一个记录集从一个数据库导出到一个csv文件中,当我尝试使用mysql workbench将其导入另一个时,我保留了以下错误消息:

Executing SQL script in server

ERROR: Error 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 ' 'Lord it Over', 'Ben', '1993-03-01', 'TRC', NULL, 1983, '1999-09-01', 'NULL', '' at line 1



INSERT INTO `TRC`.`horse` 
(`horse_id`, `registered_name`, `stable_name`, `arrival_date`, `last_known_location`, `is_ex_racer`, `birth_year`, `death_date`, `horse_comments`, `sex`, `referral_date`, `horse_height`, `arrival_weight`, `passport_no`, `microchip_no`, `is_on_waiting_list`) VALUES 
(, 'Lord it Over', 'Ben', '1993-03-01', 'TRC', NULL, 1983, '1999-09-01', 'NULL', 'NULL', 'NULL', NULL, NULL, 'NULL', 'NULL', 0)



SQL script execution finished: statements: 29 succeeded, 1 failed



Fetching back view definitions in final form.

Nothing to fetch

任何帮助都会受到赞赏,因为就我所见,它们似乎没有任何错误。

4 个答案:

答案 0 :(得分:1)

这是因为

  • VALUES以逗号开头。
  • 您错过了horse_id。如果是标识栏则删除horse_Id

尝试这样(如果horse_Id是身份)

INSERT INTO `TRC`.`horse` 
(`registered_name`, `stable_name`, `arrival_date`, `last_known_location`, `is_ex_racer`, `birth_year`, `death_date`, `horse_comments`, `sex`, `referral_date`, `horse_height`, `arrival_weight`, `passport_no`, `microchip_no`, `is_on_waiting_list`) VALUES 
('Lord it Over', 'Ben', '1993-03-01', 'TRC', NULL, 1983, '1999-09-01', 'NULL', 'NULL', 'NULL', NULL, NULL, 'NULL', 'NULL', 0)

或(如果Horse_id简单int,那么试试这个)

 INSERT INTO `TRC`.`horse` 
    (`horse_id`, `registered_name`, `stable_name`, `arrival_date`, `last_known_location`, `is_ex_racer`, `birth_year`, `death_date`, `horse_comments`, `sex`, `referral_date`, `horse_height`, `arrival_weight`, `passport_no`, `microchip_no`, `is_on_waiting_list`) VALUES 
    ('1','Lord it Over', 'Ben', '1993-03-01', 'TRC', NULL, 1983, '1999-09-01', 'NULL', 'NULL', 'NULL', NULL, NULL, 'NULL', 'NULL', 0)
     ^^^^  -- Here Horse_Id missing

答案 1 :(得分:0)

由于某种原因,您的VALUES以逗号开头

答案 2 :(得分:0)

您似乎错过了“horse_id”值。 如果该字段是Identity字段,那么您不应该在Insert Statement上提及该字段吗?

答案 3 :(得分:0)

如果您希望MySQL为horse_id字段生成auto_increment ID,则应将其完全保留在INSERT语句之外,或者为NULL中的值指定VALUES {1}}列表。您不能在列表中将该值留空。

相关问题