美国邮政编码Mysql数据类型(邮政编码) [英] Mysql Datatype for US Zip (Postal Codes)

查看:203
本文介绍了美国邮政编码Mysql数据类型(邮政编码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个网络应用程序,这是美国具体的,所以其他国家用于邮政编码的格式并不重要。我有一个我们的邮政编码的列表,我试图加载到一个数据库表,其中包括

I am writing a web application, that is US specific, so the format that other countries use for postal codes are not important. I have a list of us zip codes that i am trying to load into a database table that includes the


  • 5位数我们的邮政编码<
  • 纬度

  • 经度

  • usps分类代码

  • 状态代码

  • 城市

  • 5 digit us zip code
  • latitude
  • longitude
  • usps classification code
  • state code
  • city

邮政编码是主键,因为我将要查询。我开始使用一个中等的int 5,但是截断了具有前导零的邮政编码。

the zip code is the primary key as it is what i will be querying against. i started using a medium int 5 but that truncates the zip codes that have leading zeros.

我考虑使用char5,但是关心索引对char的性能影响

i considered using a char5 but am concerned about the performance hit of indexing against a char variable.

所以我的问题是什么是最好的mysql数据类型存储邮政编码?

so my question is what is the best mysql datatype to store zip codes as?

注意:我已经看到与邮政编码有关的其他几个问题。我只对美国的5位邮政编码感兴趣。所以没有必要考虑其他国家的邮政编码格式。

Note: i have seen it in several other questions related to zip codes. I am only interested in US 5 digit zip codes. So there is no need to take other countries postal code formats into consideration.

推荐答案

char(5)是正确的方法。字符串索引是相当快的,特别是当它是一个这么小的数据集。

char(5) is the correct way to go. String indexing is quite fast, particularly when it is such a small data set.

你是正确的,你不应该使用一个整数的邮政编码,因为它是没有真正的数字数据。

You are correct in that you should never use an integer for a zip code, since it isn't truly numeric data.

编辑添加:
查看这个是为什么不使用数字非重要数据的好原因:
使用整数列在数据库中存储美国邮政编码是个好主意?

这篇关于美国邮政编码Mysql数据类型(邮政编码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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