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
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
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
https://www.experts-exchange.com/questions/20471872/Zip-Code-Field-not-sending-leading-Zeros.html
Let me know if you have any issues
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?
ASKER
How would I indicate which column I wanted this applied to if the table name was zip_achool and the column was zip?
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks so much for the prompt reply!
https://www.experts-exchange.com/questions/22909269/Leading-Zeros-Zip-Code-MySQL.html