sql - 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.
解决方案
推荐阅读
- python - 如何为现有用户分配 id/pk 编号?
- c# - DDD - 如何对跨聚合的集合强制执行不变量
- reactjs - 无法获得发布请求的 201 状态
- sqlite - 参数类型“int”不能分配给参数类型“Expression”
' - angular - 我如何在角度 9 中取消订阅构造函数中的函数
- python - 用joblib在列表中并行编写python
- javascript - React JS 路由器更改元素的道具
- plotly - Dash Plotly Dashboard 从下拉列表中选择文件并显示数据
- javascript - 使用 Axios Post 方法 React Js 上传 Csv 文件内容?
- kubernetes - 限制每个节点的 pod 数量