我正在使用node js批量上传到mysql db。我正在插入多个行,如果在执行过程中发生任何错误,我必须更新表中的一列。我该怎么做呢。
var connection = createmysqlconnection();
var query1 = "INSERT INTO abc ("1","2");";
var query2 = "INSERT INTO xyz("3","4");";
var query3 = "INSERT INTO aaa("5","6");";
var sql = query1+query2+query3;
connection.query(sql, function (error, results, fields) {
if (error) {
console.log("Error occured");
connection.destroy();
throw error;
} else {
// connected!
console.log(results);
callback(error, results); connection.end();
}
});
1条答案
按热度按时间xfyts7mz1#
根据您的意见,您的查询不正确,请检查所需的修改;
编辑1:您可以使用以下查询
INSERT OR UPDATE
万一DUPLICATE KEY
```var query1 = "INSERT INTO abc VALUES("1","2") ON DUPLICATE KEY UPDATE val1="1", val2=2;";