码迷,mamicode.com
首页 > 数据库 > 详细

Continue SQL query even on errors

时间:2015-07-01 09:47:03      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

try
mysql --force < sample_data.sql

Mysql help section says
 -f, --force         Continue even if we get an sql error.

----------------------
You could also use INSERT IGNORE

INSERT IGNORE INTO mytable
 (primaryKey, field1, field2)
VALUES
 (‘1‘, 1, 2),
 (‘1‘, 3, 4), //will not be inserted
 (‘2‘, 5, 6); //will be inserted


----------------------
You can use INSERT... IGNORE syntax if you want to take no action when there‘s a duplicate record.

You can use REPLACE INTO syntax if you want to overwrite an old record with a new one with the same key.

Or, you can use INSERT... ON DUPLICATE KEY UPDATE syntax if you want to perform an update to the record instead when you encounter a duplicate.


----------------------

 

REF:

http://stackoverflow.com/questions/5366436/continue-sql-query-even-on-errors

Continue SQL query even on errors

标签:

原文地址:http://www.cnblogs.com/emanlee/p/4612309.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!