Entity-Relationship Model
Entity-Relationship Model
An entity is a “thing” or “object” in the real world that is distinguishable from all other objects.
For example, each person in a university is an entity. An entity has a set of properties, and
the values for some set of properties may uniquely identify an entity. For instance, a person may
have a person id property whose value uniquely identifies that person.
An entity set is a set of entities of the same type that share the same properties, or attributes.
The set of all people who are instructors at a given university, for example, can be defined as
the entity set instructor. Similarly, the entity set student might represent the set of all students in
the university.
.
A relationship set is a set of relationships of the same type. Formally, it is a mathematical
relation on n ≥ 2 (possibly nondistinct) entity sets. If E1 , E2 , . . . , En are entity sets, then a
relationship set R is a subset of
{(e 1 , e 2 , . . . , e n ) | e 1 ∈ E 1 , e 2 ∈ E 2 , . . . , e n ∈ E n }
where (e 1 , e 2 , . . . , e n ) is a relationship.
Consider the two entity sets instructor and student above Figure. We define the relationship
set advisor to denote the association between instructors and students. Figure 7.2 depicts
this association.
As another example, consider the two entity sets student and section. We can
define the relationship set takes to denote the association between a student and
the course sections in which that student is enrolled.
Mapping Cardinalities
Mapping cardinalities, or cardinality ratios, express the number of entities to
which another entity can be associated via a relationship set.
For a binary relationship set R between entity sets A and B, the mapping
cardinality must be one of the following:
One-to-one: An entity in A is associated with at most one entity in B, and an entity in B is
associated with at most one entity in A.
One-to-many: An entity in A is associated with any number (zero or more) of entities in B. An
entity in B, however, can be associated with at most one entity in A.
Composite key: This type of primary key consists of two or more attributes, such as multiple
columns.
(class, section, roll) => composite key
Foreign key: A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the
PRIMARY KEY in another table.
Attribute
In a database management system (DBMS), an attribute is a piece of data that describes an
entity. For example, in a customer database, the attributes might be name, address, and phone
number. In a product database, the attributes might be name, price, and date of manufacture.
Types of Attributes
Simple attributes: Simple attributes are those that cannot be further divided into sub-attributes.
For example, A student's roll number of a student or the employee identification number.
Composite attributes: Composite attributes are made up of two or more simple attributes. For
example, a person's address may be a composite attribute that is made up of the person's street
address, city, state, and zip code.
Single-Valued Attributes: Single-valued attributes can only have one value. For example, a
person's NID number or DOB is a single-valued attribute.
Multivalued Attributes: Multivalued attributes can have more than one value. For example, a
person may have multiple email addresses or phone numbers.
Derived attributes: Derived attributes are based on other attributes and are not stored directly
in the database.
For example: Consider a database of employees. Each employee has a date of birth, and we
might want to calculate their age. However, age is a derived attribute because it can be
determined from the date of birth.
In our university database, we have a constraint that each instructor must have exactly one
associated department. As a result, there is a double line in Figure 7.15 between instructor and
inst_dept, indicating the total participation of the instructor in inst_dept; that is, each instructor
must be associated with a department. Further, there is an arrow from inst_dept to department,
indicating that each instructor can have at most one associated department.
Similarly, entity sets course and student have double lines to relationship sets course_dept and
stud_dept respectively, as also entity set section to relationship set sec_time_slot. The first two
relationships, in turn, have an arrow pointing to the other relationship, department, while the
third relationship has an arrow pointing to time_slot.
Further, Figure 7.15 shows that the relationship set takes has a descriptive attribute grade, and
that each student has at most one advisor. The figure also shows that section is now a weak
entity set, with attributes sec_id, semester, and year forming the discriminator; sec_course is the
identifying relationship set relating the weak entity set section to the strong entity set course.
Example of Specialization – Consider an entity Account. This will have some attributes
consider them Acc_No and Balance. Account entity may have some other attributes like
Current_Acc and Savings_Acc. Now Current_Acc may have Acc_No, Balance and
Transactions while Savings_Acc may have Acc_No, Balance and Interest_Rate henceforth
we can say that specialized entities inherits characteristics of higher level entity.
MMA
Adjunct Faculty, IIUC