Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the best way to do simple update to a very Huge Table

 
Sam Kumar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to update couple of tables to convert the existing email address into lower case. Using SQL, it is very easy to do but the problem is that these tables are very huge and contains atleast 2M records. I am not sure which is the best way to do update:
1) Using SQL, something like this
update contact set email_address = lower(email_address);
2) Using SQL, but in certain number of records.
update contact set email_address = lower(email_address) where (contact _id >= 1 and contact_id <= 10000);
commit;
update contact set email_address = lower(email_address) where (contact _id >= 10001 and contact_id <= 20000);
commit;
..............so on
3) Using Java JDBC ResultSet by updating one record at a time by scrolling ResultSet. Here the ResultSet may contain atleast 2M records and I will be reading one by one and updating record one by one.
Any suggestion which one is the best or any other alternative.
Thanks in advance.
SK
 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sushil
If you don't have concerns about database down time then a sweeping SQL of the entire table should do the trick. Seems overkill to have to write an application to do the work.
If you have concerns about other applications accessing/modifying the table data during the update, then you should lock the entire table prior to running the update SQL.
Two million rows is not that much for what appears to be a relatively straightforward update.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic