客户的最佳模式 - >地址 [英] Best way to model Customer <--> Address

查看:100
本文介绍了客户的最佳模式 - >地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个客户都有一个物理地址和一个可选的邮寄地址。你最喜欢的模式是什么?

Every Customer has a physical address and an optional mailing address. What is your preferred way to model this?

选项1. 客户有外键地址


   Customer   (id, phys_address_id, mail_address_id)
   Address    (id, street, city, etc.)

选项2. 客户具有一对多的关系到地址,其中包含一个字段
来描述地址类型

Option 2. Customer has one-to-many relationship to Address, which contains a field to describe the address type


   Customer   (id)
   Address    (id, customer_id, address_type, street, city, etc.)

选项3.地址信息被正规化并存储在客户

Option 3. Address information is de-normalized and stored in Customer


   Customer   (id, phys_street, phys_city, etc. mail_street, mail_city, etc.)

我最重要的目标之一是简化对象关系映射,倾向于第一种方法。你的想法是什么?

One of my overriding goals is to simplify the object-relational mappings, so I'm leaning towards the first approach. What are your thoughts?

推荐答案

我倾向于首先采用正常化的所有常见原因。这种方法也可以更方便地在邮件详细信息上执行数据清理。

I tend towards first approach for all the usual reasons of normalisation. This approach also makes it easier to perform data cleansing on mailing details.

如果你可能允许多个地址(邮件,住宅等)或希望能够要使用有效的日期,请考虑这种方法

If you are possibly going to allow multiple addresses (mail, residential, etc) or wish to be able to use effective dates, consider this approach


   Customer   (id, phys_address_id)
   Cust_address_type (cust_id, mail_address_id, address_type, start_date, end_date)
   Address    (id, street, city, etc.)

这篇关于客户的最佳模式 - >地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆