4

Sorry for probably a very basic question, but in the literature and online, I have came across two different definitions of weak entities, which may sometimes be contradictory.

1) Weak entity is an entity which cannot exist without some other (owner) entity.
2) Weak entity does not have a primary key, but rather a partial key, and can be only uniquely identified by combining this partial key with a foreign key from owner entity.

Which one of these is true? Let us take the example of Customers->Orders relationship, where Orders have a unique OrderID. Here an Order cannot exist without a Customer, however it still has its own primary key. Would it be a strong or a weak entity then?

5

The primary key is a way to distinguish one row in a single table from all other rows in that same table. It is not a way to distinguish one row in the context of its associated rows from other tables.

Sometimes a table's primary key consists of a single column. A person's user_id would be an example.

Sometimes it is made up of several columns. A location is both latitude and longitude. This is known as a compound key. Sometimes one or more of those columns may also be a foreign key. This is termed a weak entity type.

To take your example - could a single row in the Orders table be distinguished from all other rows by the Order Number alone? Typically, yes. The order number is unique across the whole system. So given order number 8765 we know that's for customer A. This makes Order a strong entity type.

How about the OrderLine table? Given a single order line number, say "1", could we unambiguously find which Order that relates to? Typically no, because order line numbers start again for each Order. OrderLine is therefore a weak entity because its primary key (order number, order line number) requires the primary key from another related table, viz. Order.

So according to the business rules it makes no sense for an Order to exist without the Customer but according to the database rules this is OK. An OrderLine cannot exist without the Order under either set of rules.

  • Thanks for the answer. The last paragraph was especially helpful. – Shifty Scales Oct 13 '17 at 19:25
4

They are both correct definitions. Orders is a strong entity. It exists on its own. OrderItems, however, would be weak. It has an order number (foreign key) and a line number (partial key). It is only uniquely identified with both.

Weak entities have composite primary keys.

http://www.ques10.com/p/3828/we-can-convert-any-entity-set-to-a-strong-entity-s/

Consider an entity set Payment which has three attributes: payment_no, payment_date and payment_amount. Although each payment entity is distinct but payment for different loans may share the same payment number. Thus, this entity set does not have a primary key and it is an entity set. Each weak set must be a part of one-to-many relationship set. Weak entity set is required for following reasons:

  1. To avoid the inconsistencies caused by duplicating the key of the strong entity.

i. Though weak entity set can be converted into strong entity set by simply adding appropriate attributes, this approach results in the redundant storage of primary key.

ii. The primary key of a weak entity set can be inferred from its relationship with the strong entity set. If we add primary key attributes to the weak entity set, they will be present in both the entity set and the relationship set and they have to be the same.

iii. Hence, there will be redundancy in the ER diagram and we lose the concept of dependency.

iv. In the example mentioned above, adding a primary key attribute to the weak entity set Payment results in redundant storing of primary key.

  • How can an Order exist on its own without a related Customer though? Perhaps the definition of "existing on its own" is a bit ambiguous in this context. Would you please clarify what it means or point me towards some good literature? Thanks! – Shifty Scales Oct 12 '17 at 16:59
  • The Order has a unique OrderId. It does have a reference to the customer but if the application has the OrderId it can find it without knowing the CustomerId, hence it exists on it's own. The OrderItem has a line number (1,2,3, etc). Knowing that the line number of the item is 2 does not help find it unless you also know the OrderId. There could be thousands of OrderItems with line number 2. It does not have a way to identify it without the OrderId and therefore does not exist on it's own. – indiri Oct 12 '17 at 17:06
  • Thanks for clarification. Would that mean that any weak entity can be converted to a strong entity by adding a unique id? – Shifty Scales Oct 12 '17 at 17:28
  • 1
    I would say no. You can add a unique id to the OrderItems table but that row would still not have a lot of meaning outside of the context of it's order. The front end application would not be searching for the OrderItemId but would search for the whole order. The OrderItem entity is a dependent object that needs context to be useful. – indiri Oct 12 '17 at 17:33
  • 2
    See also this answer by Bill Karwin in a related question: What's the difference between identifying and non-identifying relationships? – ypercubeᵀᴹ Oct 12 '17 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.