首页 > 解决方案 > How to store address in database

问题描述

I am developing a CRM application that stores some data on companies we work with. Such as for example: CEO name and physical address of their head office. I will often need to look up for companies located in particular city and then sort the search result by street name.

I know that proper solution will most likely be something like an address column of the integer type, which will point to the address table, which itself will contain other columns like state, city, street, housing_number, office_number all of which will itself be either an integers pointing to related tables (city, state, street) or the final piece of data (housing_number, office_number).

The problem is not just the fact that I'm much more comfortable working with something like one or two linked tables, rather than using difficult JOINs across 3, 4 (like the design i supposed earlier) or even more tables, but also that i don't really see the point of not doing something like this:

| id  |      name       |  ceo_name   |    city     |     street       | house  | office |
|-----|-----------------|-------------|-------------|------------------|--------|--------|
|  1  | Company Name 1  | CEO Name 1  | New-York    | 5th Ave          |    22  |     12 |
|  2  | Company Name 2  | CEO Name 2  | New-York    | 44th St.         |    42  |     88 |
|  3  | Company Name 3  | CEO Name 3  | Boston      | Irish Lane       |     2  |     14 |
|  4  | Company Name 4  | CEO Name 4  | Washington  | Tahoe boulevard  |    54  |     19 |

What problem can i ran into if i implement such a solution? I have all atomics so if the need rises i can always implement the 3-NF solution later on.

标签: sqldatabase-designstreet-address

解决方案


类似 db 应用程序的实际模式,可能用作样板:

在此处输入图像描述


推荐阅读