开发者

Using multipe update statements from CSV vs using intermediate table

I want to update about 10,000 records. The update information is in multiple CSV files. One way to update my table is

  1. Create intermediate table and update my primary table from this table (more work)
  2. Use CSV to SQL utility which creates multiple UPDATE statements (this is tempting)

My question is, is it safe to create thousand of Update Statem开发者_如何学运维ents like this? Can it be problematic and possibly corrupt my data? It does take a lot of time to complete the action. One such online tool is this

UPDATE MyTable SET change_field = 'ABC' WHERE other_field = '1';
UPDATE MyTable SET change_field = 'ABC' WHERE other_field = '2';
UPDATE MyTable SET change_field = 'DEF' WHERE other_field = '3';


There shouldn't be any problem running a large number of statements like that unless the database you are using has some kind of limitation specifically documented. In general, though, running 10,000 update statements would not be considered much of a load for most databases. You might want to consider running the statements in a transaction so that if there are problems you can roll back the changes.

It would be good to make sure that other_field has an index on it. Otherwise, the update statements could be slow if the table is very large (each update would likely require a full table scan if there is no index on that field).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜