views:

60

answers:

1

I'm planning a database who has a couple of tables who contain plenty of address information, city, zip code, email address, phone #, fax #, and so on (about 11 columns worth of it), a table is an organizations table containing (up to) 2 addresses (legal contacts and contacts they should actually be used), plus every user has the same information tied to him.

We are going to have to run some geolocation stuff on those addresses too (like every address that's within X Kilometers from another address).

I have a bunch of options, each with its own problem:

  1. I could put all the information inside every table but that would make for tables with a very large amount of columns which I'd have problems indexing, and if I change my address format it'll take a while to fix it.
  2. I could put all the information inside an array and serialize it, then store the serialized information in one field, same problem with the previous method with a little less columns and much less availability through mysql queries
  3. I could create a separate table with address information and link it to the other tables either by

    1. putting an address_id column in the users and organizations table
    2. putting a related_id and related_table columns in the addresses table

    That should keep stuff tidier, but it might create some unforeseen problems with excessive joining or whatever.

Personally I think that solution 3.2 is the best, but I'm not too confident about it, so I'm asking for opinions.

A: 

Option 2 is definitely out as it would put the filtering logic into your codes instead of letting the DBMS handle them.

Option 1 or 3 will depend on your need.

if you need fast access to all the data, and you usually access both addresses along with the organization information, then you might consider option 1. But this will make it difficult to query out (i.e. slow) if the table get too big in mysql.

option 3 is good provided you index the tables correctly.

iWantSimpleLife
I see, and what about 3.1 or 3.2?
Madness
I'd say 3.1. Or create Organization_Addresses (Org_ID, Addr_ID, Order) to allow for several addresses for an Organization; and another User_Addresses.
pascal
Do you have the same address for multiple organizations or will each address be only for 1 organization? From the question above, it is clear that each organization has multiple addresses.If the address can only belong to 1 organization, then you should be using a foreign key in the address table to link to the organization table.If each address can belong to multiple organization, then you will need to create a seperate table to link the addresses and the organizations, as mentioned in Pascal's comment.
iWantSimpleLife