Patrick made some very good points, I'll just expand on them a little:
1: set_time_limit(seconds) will set the max execution time of a script. Setting seconds to zero will result in a script running forever and ever, amen, or until it is finished. I usually use something smaller like 300 or 1800 (5 and 30 minutes resp.)
2: If you are selecting one record at a time and inserting it into the other table with an insert, this is VERY inneficient. If you can use select into and insert into statements, this will speed things up a bunch.
3: You don't mention which database you are using. Each has tricks and tips to get these kinds of things to run faster, but they don't tend to cross over from one dbms to another well. So, which dbms are you running?