MySQL drops leading zeroes from imported US zip codes


After importing a table from a csv import, MySQL drops the leading zero from those codes that contain it. A quick way to fox this is to use a SQL query to update the table.

Log into the correct database in phpMyAdmin and open the table in question
Choose the SQL option from the tabs at the top
Paste the following query in to the box
UPDATE table_name SET ZipCode = concat(‘0’,ZipCode) WHERE length(ZipCode) = 4


Modify the statement to fit your situation, including table name and the zip code field name if needed. If you look at the code, you can tell that this will only work for a 5 digit code.

Execute statement and check the result.