Weak entities and foreign keys

5.7k Views Asked by At

Quoting Wikipedia, a weak entity "must use a foreign key in conjunction with its attributes to create a primary key." , and "is existence-dependent on another entity". But can't an entity be existence-dependent on another entity without having (part of) the PK the FK ?

In the classical Order - OrderLine - Product relation, OrderLine is a weak entity because its PK consists of the two FK's from the others entities, say orderID and productID.

But what about the Order entity ? Let's say it looks like this:

Order( orderID   - not null, Primary key,
    costumerID - not null, Foreign key,
    date,
    status,
    ...)

It's clear enough that an order can't exist without a costumer(costumerID), but at the same time, costumerID is not part of the Primary key.

  1. So, in this case, is the Order entity a weak one, or not ?
  2. What if we had omitted the NOT NULL constraint of the FK customerID ? Order wouldn't be a weak entity anymore, right ?
1

There are 1 best solutions below

0
On

An entity can be existence-dependent on (a relationship with) another entity without being a weak entity. This is called total participation, and indicated in ER diagrams with a double role line.

In your example, OrderLine would be a weak entity if its PK consisted of orderID and a distinguishing attribute, e.g. line_number. If its PK consisted of two FKs, we would call it a relationship instead.

Your Order example shows total participation in its relationship with Customer (the relationship is represented by the two entity key columns (orderID,customerID)). It's not a weak entity since it has its own identifier, i.e. orderID. If we omitted the NOT NULL constraint, Order would be in partial participation in its relationship with Customer.

Also see my answer to is optionality (mandatory, optional) and participation (total, partial) are same?