Link to home
Start Free TrialLog in
Avatar of ecperi58
ecperi58

asked on

Entering a number string with 0 in front in MySQL DB

Hi,

I am trying to import a csv file of zip codes into a MySQL database. The zip codes that start with 0 are being entered without the 0's in front. Can I remedy this?

Thanks
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

The solution I linked to above assumes your zip code column is an integer type. Alternatively, you can change the column to be a varchar - there's an example of this too:
https://www.experts-exchange.com/questions/20471872/Zip-Code-Field-not-sending-leading-Zeros.html

Let me know if you have any issues
Avatar of ecperi58
ecperi58

ASKER

My table has 2 columns, one called school_id and one called zip. If I do the ZEROFILL will it add a zero to both fields? I would just like the 0 added to the zip codes on the zip column that did not import the beginning 0 (sometimes 2 beginning zeros).
The zerofill option just applies to an individual column, however it will apply to all rows in the table, up to the number of characters indicated by the column length eg int(5) would add zeroes to make it up to 5 characters. Will this meet your requirements?
How would I indicate which column I wanted this applied to if the table name was zip_achool and the column was zip?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks so much for the prompt reply!