简体   繁体   中英

Updating one field per row, 1 million + rows

I have a large address database I need to "clean up".

Example, the address contains the county but not always in the same field, sometimes its in address3 and sometimes address4 or not at all.

I've put everything in a table, created a new field called County and the php loads the data (1000 rows at a time for testing) into an array.

It searches for "CO." in address3 or 4 and if found then copies the contents of that cell to "County". So far so good.

The problem is that it runs extremely slow, I use the following as the UPDATE:

$update = "UPDATE opportunities SET County='" . $address4 . "' " . "WHERE id=" . $id;

Is there a faster way to do this than running the above line for each entry?

It would be faster to do it directly in SQL, but by its nature this sort of string searching will be pretty slow:

UPDATE opportunities
SET    County = CASE
         WHEN address3 LIKE '%CO.%' THEN address3
         WHEN address4 LIKE '%CO.%' THEN address4
       END

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM