• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic