美国邮政编码的最佳列类型是什么? [英] What is the best column type for a United States ZIP code?

查看:362
本文介绍了美国邮政编码的最佳列类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MySQL数据库中存储邮政编码(在美国境内)。 保存空间是首要任务。这是使用VARCHAR的更好选项 - 限制为最大长度为6位或使用INT或使用MEDIUM Int。邮政编码不会用于任何计算。邮政编码将用于插入(一次),更新(如果需要)和检索 - 一次(但可以多次)。

I want to store Zip Code (within United States) in MySQL database. Saving space is a priority. which is better option using VARCHAR - limited to maximum length of 6 digit or using INT or using MEDIUM Int . The Zip code will not be used for any calculation. The Zip code will be used to insert (Once), Updated (if required) and Retrieved - Once (but it can be more than once) .

哪个是更好的选择在这里使用 VARCHAR或INT或MEDIUM在MYSQL ?请提出其他建议吗?

Which is better option to use here VARCHAR or INT or MEDIUM IN MYSQL ? Please suggest anything else ?

推荐答案

将邮政编码存储为数字值存在一些问题。

There are a few problems with storing a zip code as a numeric value.


  1. 邮政编码有扩展名,这意味着它们可以是 12345-6789 。您不能将破折号存储在数字数据类型中。

  2. 有许多邮政编码以零开头,如果将其存储为int,则会丢失前导零。

  3. 您不需要添加/减去等邮政编码或使用数字函数。

  1. Zip Codes have extensions, meaning they can be 12345-6789. You cannot store a dash in a numeric datatype.
  2. There are many zip codes that start with a zero, if you store it as an int you are going to lose the leading zero.
  3. You do not add/subtract, etc zip codes or use numeric functions with them.

我会将邮政编码存储为 varchar(5) varchar(10)

I would store a zip code as a varchar(5) or varchar(10).

作为旁注,我不知道为什么你会选择 varchar(6),你有没有理由选择一个不寻常的标准邮政编码为5或10时的长度是否为?

As a side note, I am not sure why you would select varchar(6), do you have a reason for selecting an unusual length when standard zip codes are 5 or 10 with the extension?

这篇关于美国邮政编码的最佳列类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆