What is a weak entity set?
A weak entity set is an entity set that does not have a primary key. The primary key of a weak entity set is a combination of the primary key of the strong entity set on which it depends and its own attribute.
Characteristics of a weak entity set
A weak entity set is a set of entities that does not have a primary key. A weak entity set cannot be uniquely identified by its own attributes, and must be identified by a foreign key from another (owner) entity.
The following image shows an example of a weak entity set:
In the example above, the oval represents the owner entity (Emp), and the rectangles represent the weak entity sets (Dept and Project). The lines connecting the rectangles to the oval represent the foreign key relationships.
A weak entity set always has a relationship with another entity (the owner), and this relationship is represented by a foreign key. In the example above, Emp is the owner of both Dept and Project, and Dept and Project are both weakentity sets.
Why weak entity sets do not have a primary key?
In general, a weak entity set does not have a primary key. This is because the primary key of a weak entity set is derived from its relationship with another entity set. Let’s take a closer look at why this is the case.
Primary keys are generated by the system
Primary keys are generated by the system, and not by the user. This is because the system needs to ensure that each row in the table is unique, and it does this by assigning a primary key.
How to identify a weak entity set?
In a database, an entity is a piece of data-an object or concept about which information is stored. A weak entity is an entity that can’t be uniquely identified by its attributes alone; therefore, it must use a foreign key in conjunction with its attributes to create a primary key.
Check if the entity set has a partial key
In order to identify a weak entity set, you first need to check if the entity set has a partial key. A Partial Key is a key composed of a subset of the attributes of the entity. If the answer is yes, then it means that the entity set is weak.
How to store data in a weak entity set?
In a weak entity set, each entity is weak because it does not have a primary key of its own. In order to store data in a weak entity set, we need to create a separate table for the weak entity set. The table will have a composite primary key made up of the primary key of the strong entity set and the foreign key of the weak entity set.
Use a composite key
A weak entity is one that cannot be uniquely identified by its own attributes and must use a foreign key from another entity in order to be uniquely identified. To store data in a weak entity set, you must use a composite key, which is a key that consists of the primary key of the parent entity plus the attribute(s) of the weak entity that uniquely identify it.