Lesson 5
Lesson 5
Chemistry
Tom Works Department
Relationship
● Relationship is nothing but an association among two
or more entities. E.g., Tom works in the Chemistry
department.
Relationship - Degree
● Degree: Number of entity types that participate in a
relationship
● Three cases
a. Unary: between two instances of one entity
b. Binary: between the instances of two entity
c. Ternary: among the instances of three entity
Relationship - Degree
● Three cases
a. Unary: between two instances of one entity
b. Binary: between the instances of two entity
c. Ternary: among the instances of three entity
Relationship - Cardinality
● Cardinality: Defines the numerical attributes of the
relationship between two entities or entity sets.
Relationship - Cardinality
● Relationships can also have a property called
cardinality. Cardinality refers to the number of allowed
related rows between entities.
● Maximum cardinality: The highest number permitted.
● Minimum cardinality: The smallest number permitted.
● RDBMSs really don’t have ways to enforce cardinality
rules directly. Usually, these kinds of rules are enforced
by means of triggers and other extra-database code.
Relationship - Cardinality
● For example, say an Account entity can have no
more than five email addresses in a related Email
entity. That would mean that the relationship has a
maximum cardinality of five. Let’s also say that
each account must have at least one email
account. That would make the minimum
cardinality of the relationship one.
Relationship - Cardinality
● Cardinality: Defines the numerical attributes of the
relationship between two entities or entity sets.
Relationship - Participation/Connectivity
Relationship - Participation/Connectivity
Relationship - Participation/Connectivity
Relationship - Participation/Connectivity
Relationship - Participation/Connectivity
Relationship - Participation/Connectivity
● Zero to One
● Exactly One
Relationship - Participation/Connectivity
Resource Table
Book Table
Magazine Table
Relationship - Participation/Connectivity
Relationship - Participation/Connectivity
● Zero or More
● At least one or
more
Relationship - Participation/Connectivity
● One to many
Relationship - Participation/Connectivity
● One to many
Department Table
Employee Table
Relationship - Participation/Connectivity
● Many to Many
● Many–to-many relationships are common, and they
are legitimate relationships in logical terms, but no
database can implement them. A many-to-many
relationship means that each record in the primary
entity can have many related records in a second
entity and each record in the second entity can have
many related records in the primary entity.
Relationship - Participation/Connectivity
Relationship - Participation/Connectivity
● In any RDBMS, a many-to-many relationship must be resolved
into two one-to-many relationships. This is done by creating a
linking entity. In this case, the Magazine and the Subscriber
entities are linked by a Subscription entity. A subscriber
subscribes to one or more magazines. A magazine can be
subscribed to by zero-to-many subscribers. Often, as in this
case, creating the linking entity reveals a forgotten or
undiscovered entity, Subscription is more than a linking entity.
It is a legitimate entity with attributes of its own.
Relationship - Participation/Connectivity
Magazine Table
Subscriber Table
Subscription Table
Relationship - Participation/Connectivity
ER Model in 3 Levels of Abstraction