Earthtracker's Blog

Just another WordPress.com weblog

MYSQL Store Procedure to execute multiple queries in Loop

If you have auto increment / serialize ID and need to execute multiple queries in loop, you may try:

BEGIN
    DECLARE c int ;                     
    SET c = 1 ;                          
    WHILE c<100 DO
      update TABLE set field_name = 'test' where id=c;
      SET c = c + 1 ;
    END WHILE ;
END
Leave a comment »