Re: Question: Entities With Common Attributes

From: David Cressey <david_at_dcressey.com>
Date: Wed, 04 Apr 2001 13:51:35 GMT
Message-ID: <HFFy6.37253$2X4.160272_at_petpeeve.ziplink.net>


> A database model for a company sales obviously contains an entity
 "customer"
>
> But, in this case, there are 2 types of customer - "businesses" and
> "individuals"
> Different attributes are recorded for each type

You could model this, theoretically, with five tables:customers, businesses, individuals,
customer-businesses, and customer-individuals.

Customers contains data common to customers regardless of type. Key is customer-id
Businesses contain data particular to businesses. Key is Business-id. Individuals contain data particular to individuals, Key is Individual-id.

Customer-businesses is a relation with two foreign keys:  Customer-id and
Business-id.
Customer-individuals is a relation with two foreign keys: Customer-id and
Individual-id.

In the "real world", I would tend to implement this as a single table, with separate columns for data about individuals and businesses, and leave NULL in the slots that aren't pertinent to the type of customer. But that design will fail when the requirements change such that you want to store data about individuals or businesses that are NOT customers (e.g. employees, vendors).

--
Regards,
    David Cressey
    www.dcressey.com
Received on Wed Apr 04 2001 - 15:51:35 CEST

Original text of this message