2013-04-24 36 views
0

假設我有這樣的MySQL的插入多行的數據被部分地保存

INSERT INTO mytable(`title`, `name`) VALUES // row1 
(`title1`, `name1`), // row 2 
(`title2`, `name2`), // row 3 
(`title3`, `name3 is too long for the table corresponding field`); // row 4 

查詢,並試圖保存到數據庫,我得到的錯誤,像data truncated for column name,所以我想問是否行(第2行和第3行)和/或第三行的title字段將被保存在表格中,或者在出現此錯誤的情況下,不會保存任何數據(如果先掃描它,'檢查'是否可以正確保存所有數據,然後試圖保存) 謝謝

+3

你爲什麼不嘗試一下? – 2013-04-24 17:20:06

+0

它不會保存任何信息 – DevelopmentIsMyPassion 2013-04-24 17:23:57

+0

@AshReva它爲我保存到數據庫。 – hjpotter92 2013-04-24 17:24:37

回答

1

在MySQL 5.6.13以下SQL無法插入任何記錄:

INSERT INTO mytable(title, name) VALUES 
('title1', 'name1'), 
('title2', 'name2'), 
('title3', 'name3 is too long for the table corresponding field'); 

,如果你希望數據被截斷並已全部三個記錄插入使用「忽略」:

INSERT IGNORE INTO mytable(title, name) VALUES 
('title1', 'name1'), 
('title2', 'name2'), 
('title3', 'name3 is too long for the table corresponding field');