Why do developers put asymmetric items into a single database table? [closed]

A pattern I’ve seen several times is:

  • Customer table – CUSTOMER ID,
  • Contact table – CUSTOMER_ID, CONTACT_TYPE, CONTACT_NUMBER, OTHER

The use case for the tables is:

SELECT
Home_Num.CONTACT_NUMBER as PHONE_NUMBER,
Mobile.CONTACT_NUMBER as MOBILE_NUMBER,
Email.OTHER as EMAIL,
<other fields>
FROM Customer
LEFT JOIN Contact as Home_Num
    ON Customer.CUSTOMER_ID = Home_Num.CUSTOMER_ID
    and Home_Num.CONTACT_TYPE = 'Home'
LEFT JOIN Contact as Mobile
    ON Customer.CUSTOMER_ID = Mobile.CUSTOMER_ID
    and Mobile.CONTACT_TYPE = 'Mobile'
LEFT JOIN Contact as Email
    ON Customer.CUSTOMER_ID = Email.CUSTOMER_ID
    and Email.CONTACT_TYPE = 'Email'

Usually there is an assumption throughout the rest of the application that “each customer only has one home number” which I assume is made to simplify the UI design. In principle there could be infinitely many contacts attached to each customer but this pattern still turns up in places where that isn’t a possibility.

Is there a reason people design things this way? I’ve seen too many instances like this to assume it is accidental.

1

Considering there are PHONE_NUMBER and MOBILE_NUMBER in the query, probably the PHONE_NUMBER refers to the land line that is common to have a one-to-one relation with the customer, it wouldn’t be unusual neither a one-to-many relation between PHONE_NUMBER and Customer. It isn’t a UX issue, it is a real model.

New contributor

user453247 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Is there a reason people design things this way?

Because, “What is your personal UUID?” doesn’t produce useful answers as frequently as, “What phone number do we have for you?”

If it did tracking people would be so much easier. But in this world people can’t agree on a single system to ID people with and people refuse to memorize an ID for every darn system they interact with.

Which is why you have to bribe people with discounts to get them to carry around loyalty cards with the ID you issued to them.

Without a scheme like that we need something they already have memorized. Most people have and can remember their phone number. But yes, some people have more than one. Some numbers are associated with more than one person.

So no, this is not at all a perfect ID. This is just something to search for in an attempt to pull up their record. Without it you have to hope you’re not the first person to bother to ask them how to spell their name. *

* Transliteration is not perfect either.

 

which I assume is made to simplify the UI design

The UI is just fields that you type in. The UI doesn’t care. But this is a User Experience issue. The fewer questions it takes to get to the right record the better.

I typically see this pattern for composite objects for example a customer can have separate billing and shipping addresses (each with multiple fields).

Assuming each customer has exactly one billing and one shipping address this could be represented as a single table with prefixed field names billing_... and shipping_... or it could be represented using two tables.

Generally more tables offer more flexibility for future enhancements/changes and less tables result in simpler queries (I am certain there are exceptions to both of these points).

With a reasonable amount of effort, either option can be refactored to the other one, hence it becomes a matter of opinion about which solution is “better” or “more flexible” and there will be a question about if you are going to need the extra flexibility.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Why do developers put asymmetric items into a single database table? [closed]

A pattern I’ve seen several times is:

  • Customer table – CUSTOMER ID,
  • Contact table – CUSTOMER_ID, CONTACT_TYPE, CONTACT_NUMBER, OTHER

The use case for the tables is:

SELECT
Home_Num.CONTACT_NUMBER as PHONE_NUMBER,
Mobile.CONTACT_NUMBER as MOBILE_NUMBER,
Email.OTHER as EMAIL,
<other fields>
FROM Customer
LEFT JOIN Contact as Home_Num
    ON Customer.CUSTOMER_ID = Home_Num.CUSTOMER_ID
    and Home_Num.CONTACT_TYPE = 'Home'
LEFT JOIN Contact as Mobile
    ON Customer.CUSTOMER_ID = Mobile.CUSTOMER_ID
    and Mobile.CONTACT_TYPE = 'Mobile'
LEFT JOIN Contact as Email
    ON Customer.CUSTOMER_ID = Email.CUSTOMER_ID
    and Email.CONTACT_TYPE = 'Email'

Usually there is an assumption throughout the rest of the application that “each customer only has one home number” which I assume is made to simplify the UI design. In principle there could be infinitely many contacts attached to each customer but this pattern still turns up in places where that isn’t a possibility.

Is there a reason people design things this way? I’ve seen too many instances like this to assume it is accidental.

1

Considering there are PHONE_NUMBER and MOBILE_NUMBER in the query, probably the PHONE_NUMBER refers to the land line that is common to have a one-to-one relation with the customer, it wouldn’t be unusual neither a one-to-many relation between PHONE_NUMBER and Customer. It isn’t a UX issue, it is a real model.

New contributor

user453247 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Is there a reason people design things this way?

Because, “What is your personal UUID?” doesn’t produce useful answers as frequently as, “What phone number do we have for you?”

If it did tracking people would be so much easier. But in this world people can’t agree on a single system to ID people with and people refuse to memorize an ID for every darn system they interact with.

Which is why you have to bribe people with discounts to get them to carry around loyalty cards with the ID you issued to them.

Without a scheme like that we need something they already have memorized. Most people have and can remember their phone number. But yes, some people have more than one. Some numbers are associated with more than one person.

So no, this is not at all a perfect ID. This is just something to search for in an attempt to pull up their record. Without it you have to hope you’re not the first person to bother to ask them how to spell their name. *

* Transliteration is not perfect either.

 

which I assume is made to simplify the UI design

The UI is just fields that you type in. The UI doesn’t care. But this is a User Experience issue. The fewer questions it takes to get to the right record the better.

I typically see this pattern for composite objects for example a customer can have separate billing and shipping addresses (each with multiple fields).

Assuming each customer has exactly one billing and one shipping address this could be represented as a single table with prefixed field names billing_... and shipping_... or it could be represented using two tables.

Generally more tables offer more flexibility for future enhancements/changes and less tables result in simpler queries (I am certain there are exceptions to both of these points).

With a reasonable amount of effort, either option can be refactored to the other one, hence it becomes a matter of opinion about which solution is “better” or “more flexible” and there will be a question about if you are going to need the extra flexibility.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật