开发者

Shall I put contact information in a separate table?

开发者 https://www.devze.com 2023-01-07 01:37 出处:网络
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 or

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 solutio开发者_开发知识库n 3.2 is the best, but I'm not too confident about it, so I'm asking for opinions.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号