views:

1705

answers:

8

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.

A: 

You need to provide a bit more details about how you are planning to use the data. For example, fields like City, State, Country can either be text in the single table, or be codes which are linked to a separate table with a Foreign Key.

Simplest would be

AddressLine01 (Required, Non blank) AddressLine02 AddressLine03 Landmark City (Required) Pin (Required) Province_District State (Required) Country (Required)

All the above can be Text/Unicode with appropriate field lengths.

Phone Numbers as applicable.

Abhinav
Only a bunch of countries has states.
Cem Kalyoncu
+1  A: 

Here is a partial picture of my data model for handling both domestic (US) and international addresses.

http://www.flickr.com/photos/86748774@N00/2789563061/

Tim Cochran
+10  A: 

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.

DrPizza
Greater London may not be a county but, unless you live in the City Of London itself, you'll probably find that you do actually live in Surrey, Kent, Essex or such-like.
belugabob
Putting in different administrative subdivisions is handy for filtering by region. How else are you going to know what part of the world/country you sell most products to?
Joeri Sebrechts
At best, make country selectable. Countries are created only infrequently.
DrPizza
Oh, and no, I don't live in Surrey, Kent, Essex, or any of those. I live in the London borough of Lambeth, which is part of Greater London but not a county.
DrPizza
@DrPizza, the pedant in me has to tell you that living in Lambeth, you live in the historic county of Surrey, but the administrative county of Greater London. See http://www.abcounties.co.uk/
darasd
I also live in the historic country of Britannia, and prior to that, Albion.Presently (and for quite some time) I do not live in Surrey at all. Just because the area once used to be Surrey does not mean it now is. Historic counties are dead and buried. Nobody knows, or cares, about them. Indeed, even Londoners who _are_ in Surrey do not identify as such.
DrPizza
A: 

According to the Royal Mail, If you want to be sure of fitting in a UK postal address, you need 7 lines of 56 characters.

Matt Lacey
+3  A: 

In the past I've modeled forms that needed to be international after the ups/fedex shipping address forms on their websites (I figured if they don't know how to handle an international order we are all hosed). The fields they use can be used as reference for setting up your schema.

The Brawny Man
+4  A: 

In general, you need to understand why you want an address. Is it for shipping/mailing? Then there is really only one requirement, have the country separate. The other lines are freeform, to be filled in by the user. The reason for this is the common forwarding strategy for mail : any incoming mail for a foreign country is forwarded without looking at the other address lines. Hence, the detailed information is parsed only by the mail sorter located in the country itself. Like the receiver, they'll be familiar with national conventions.

(UPS may bunch together some small European countries, e.. all the Low Countries are probably served from Belgium - the idea still holds.)

MSalters
A: 

Postcodes can be complicated - for instance, there is no general postcode system in the Republic of Ireland, though postcodes exist for Dublin (all numbered 1-24, with the exception of 6W).

A: 

I think adding country/city and address text will be fine. country and city should be separate for reporting. Managers always ask for these kind of reports which you do not expect and I dont prefer running a LIKE query through a large database.

Cem Kalyoncu