什么是“最好的”的方式来存储国际地址在数据库? [英] What is the "best" way to store international addresses in a database?

查看:180
本文介绍了什么是“最好的”的方式来存储国际地址在数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最好的方式在数据库中存储国际地址?以模式的形式回答,并解释为什么你选择规范化(或不规范)你的方式。


解决方案

无格式文本。



验证所有世界的邮政编码硬;一个固定的国家名单过于政治敏感;强制性的州/地区/其他行政区划只是明显不适当(我常常问我住在哪个县 - 当我不,因为大伦敦不是一个县)。



更重要的是,这是没有必要的。您的应用程序极不可能以任何严重的方式对地址建模。如果你想要一个邮政地址,请要求邮政地址。大多数人不是那么愚蠢的,除了邮政地址之外的东西,如果他们这样做,他们可以亲吻他们新购买的项目再见。



例外,如果你正在做一些自然限制到一个国家的东西。在这种情况下,您应该要求{postcode,house number}对,这足以识别邮政地址。我想你可以用美国的扩展邮政编码实现类似的东西。


What is the "best" way to store international addresses in a database? Answer in the form of a schema and an explanation of the reasons why you chose to normalize (or not) the way you did. Also explain why you chose the type and length of each field.

Note: You decide what fields you think are necessary.

解决方案

Plain freeform text.

Validating all the world's post/zip codes is too hard; a fixed list of countries is too politically sensitive; mandatory state/region/other administrative subdivision is just plain inappropriate (all too often I'm asked which county I live in--when I don't, because Greater London is not a county at all).

More to the point, it's simply unnecessary. Your application is highly unlikely to be modelling addresses in any serious way. If you want a postal address, ask for the postal address. Most people aren't so stupid as to put in something other than a postal address, and if they do, they can kiss their newly purchased item bye-bye.

The exception to this is if you're doing something that's naturally constrained to one country anyway. In this situation, you should ask for, say, the { postcode, house number } pair, which is enough to identify a postal address. I imagine you could achieve similar things with the extended zip code in the US.

这篇关于什么是“最好的”的方式来存储国际地址在数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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