943,791 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 829
  • MySQL RSS
Oct 10th, 2008
0

update in steps? is it possible ?

Expand Post »
Hi ,

Wishes!

I am doing a iterative calculation and in the last iteration, i update few of my tables. What i am trying to do is , make this update more perfect.

Is it possible for me to do updates in small steps with using LIMIT. i do not find this anywhere mentioned and do not have a idea of my own. say i got 10000 records, i get this count and update in steps of 1000 each time as might be this would prevent from a update table to lock the entire table for long.

My table is innoDB type and i would appreciate some nice examples or pointers in this regard.

Harisaff
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
hbmarar is offline Offline
187 posts
since Apr 2005
Oct 13th, 2008
0

Re: update in steps? is it possible ?

try this code:
php Syntax (Toggle Plain Text)
  1. $qry=mysql_query("SELECT * FROM yourtablename ");
  2. $num=mysql_num_rows($qry);
  3. $start=0;
  4. $len=1000;
  5. $value=$_POST['field']
  6. while($start<$num)
  7. {
  8. $f="update tablename set field='".$value."' LIMIT $start,$len";
  9. $start=$start+1000;
  10. $len=$len+1000;
  11. }
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Nov 26th, 2008
0

Re: update in steps? is it possible ?

Hi Shanti,

Thanks for the reply but I needed an advance logic for my script was in need of an alternative with temporary tables and the total record set to play with was 64 lakh records. Also, 5 iterations, with 5 temporary table and advanced 3 line formula computation gets it all challenging.

By the way, I had figures out for iterations and is well, now needs the final write back to master more replication sync.. working on that front.

Thanks again.

Regards

Harish
try this code:
php Syntax (Toggle Plain Text)
  1. $qry=mysql_query("SELECT * FROM yourtablename ");
  2. $num=mysql_num_rows($qry);
  3. $start=0;
  4. $len=1000;
  5. $value=$_POST['field']
  6. while($start<$num)
  7. {
  8. $f="update tablename set field='".$value."' LIMIT $start,$len";
  9. $start=$start+1000;
  10. $len=$len+1000;
  11. }
Reputation Points: 10
Solved Threads: 0
Junior Poster
hbmarar is offline Offline
187 posts
since Apr 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Pulling related data from relational dB re: thread: Problems with a many-to-many inse
Next Thread in MySQL Forum Timeline: How to countdown to a date in MySQL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC