DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   MySQL (http://www.daniweb.com/forums/forum126.html)
-   -   update in steps? is it possible ? (http://www.daniweb.com/forums/thread150311.html)

hbmarar Oct 10th, 2008 3:43 am
update in steps? is it possible ?
 
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

Shanti Chepuru Oct 13th, 2008 3:34 am
Re: update in steps? is it possible ?
 
try this code:
$qry=mysql_query("SELECT * FROM yourtablename "); 
$num=mysql_num_rows($qry);
$start=0;
$len=1000;
$value=$_POST['field']
while($start<$num)
{
$f="update tablename set field='".$value."' LIMIT $start,$len";
$start=$start+1000;
$len=$len+1000;
}

hbmarar Nov 26th, 2008 1:28 am
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
Quote:

Originally Posted by Shanti Chepuru (Post 711393)
try this code:
$qry=mysql_query("SELECT * FROM yourtablename "); 
$num=mysql_num_rows($qry);
$start=0;
$len=1000;
$value=$_POST['field']
while($start<$num)
{
$f="update tablename set field='".$value."' LIMIT $start,$len";
$start=$start+1000;
$len=$len+1000;
}



All times are GMT -4. The time now is 11:21 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC