简体   繁体   English

检查数据并将其插入MySQL数据库节点的有效方法

[英]Efficient way to check and insert data into MySQL database node

First Way: 第一种方式:

  1. Fetch all the records from the database and create a result array. 从数据库中获取所有记录,并创建一个结果数组。
  2. Loop the new inserting array and check the unique id is exist or not with the above result array then inserting to the DB. 循环新的插入数组,并使用上述结果数组检查唯一ID是否存在,然后插入数据库。

Second Way: 第二种方式:

  1. Loop the new inserting array and check the unique id is exist or not in the database then insert into the database. 循环新的插入数组,并检查数据库中是否存在唯一ID,然后将其插入数据库。

Note: Inserting data will be very less compared to the database table data. 注意:与数据库表数据相比,插入数据要少得多。

Please suggest any best way to do it. 请提出任何最佳方法。

An implemetation of @NigelRen idea @NigelRen想法的实现

insert into destTable  (id, coln,...)
select st.id,st.coln,...
from srcTable st
left join destTable dt on st.id=dt.id
where dt.id is null

where id is the relation one-to-one between the two tables 其中id是两个表之间的一对一关系

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM