3

I'm currently learning about strong and weak entity types in the context of RDBMS. While reading, I came across this statement:

"A weak entity is dependent on a strong entity to ensure its existence. Unlike a strong entity, a weak entity does not have any primary key"

I'm starting to grasp the differences between strong and weak entity types and this statement seems incorrect to me. Specifically, it states that a weak entity does not have a primary key. However, shouldn't every entity possess a primary key? i.e., there MUST be combination of attributes that will provide uniqueness. So saying that a weak entity type does not have a primary key makes no sense.

However, it seems like the real definition of a weak entity type is an entity who's primary key MUST require a foreign key.

Is my definition of a weak entity correct?

1 Answer 1

4

Strong Entities and Weak Entities are not Relational Database ideas. They are more abstract data modeling ideas than can be implemented in a Relational Database, or a Document Database, or an OO object model, etc.

When you implement Weak Entities in a Relational Database the most correct (if not the most common) pattern is for the Weak Entity's primary key to include the Strong Entity's primary key columns as the leading columns. EG

create table SalesOrder(Id int primary key,...)
create table SalesOrderDetail
(
  SalesOrderId int not null references SalesOrder, 
  Id int not null,
  primary key pk_SalesOrderDetail(SalesOrderId, Id),
  ...
)

In practice you often see

create table SalesOrder(Id int primary key,...)
create table SalesOrderDetail
(
  Id int primary key,
  SalesOrderId int references SalesOrder, 
  ...
)

Which is just wrong and sloppy, but can be made right with

create table SalesOrder(Id int primary key,...)
create table SalesOrderDetail
(
  Id int primary key,
  SalesOrderId int not null references SalesOrder, 
  index ix_SalesOrderDetail_SalesOrder (SalesOrderId),
  ...
)

By which point you can see that it's easy to make mistakes with this pattern, and it requires two indexes instead of just one.

1
  • I think you've confirmed my hunch. Thank y ou.
    – Izzo
    Sep 18, 2022 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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