Q:

What's wrong with this MySQL query? (Trying to re-add leading 0's to zip codes)

I have a table of zip codes, and alot of fields in it lost their leading zero's during import. I have a query that should re-add the zeros to the left and I've run this query with no errors, however it says 0 rows were affected:
UPDATE `Zip Codes` SET Code = right(concat("00000",Code), 5) WHERE length(Code) < 5;

Anyone able to see what the problem might be?

A:

Zip codes, like telephone numbers, should always be stored as VARCHAR an not INT.
Why?
They aren't integers, and don't represent actual numbers. You aren't really sorting them, you aren't incrementing them or adding them together, they don't represent an amount of something, they are merely codes - and can theoretically contain any character including alphas and punctuation.
If they were integers, then 00123 would mean exactly the same as 123.
For example, check out the Wikipedia page on Zip Code Formats, there are many varieties of format and length. Even in the U.S., there are extensions that will make them be more than the 5 digits you've alotted.
VARCHAR(32) should be adequate.

