Unit2 CP 1 DBMS
Unit2 CP 1 DBMS
Unit2 CP 1 DBMS
1
Entity-Relationsh
p
Model
• A database can be modeled as:
– a collection of entities,
– relationship among entities.
• An entity is an object that exists and is
distinguishable from other objects.
– Example: specific person, company, event, plant
5
Attributes
An entity is represented by a set of attributes.
An attribute is a property that describes an entity.
All attributes have values.
For example, a student entity may have name, class, age as
attributes.
Ex:
customer = (customer_id, customer_name customer_street,
customer_city )
loan = (loan_number, amount )
7
Composite Attributes
■ If the attributes are not divided into subparts is
called simple.
■ If the attributes are divided into subparts then
composite
8
Single-valued and multi-valued
attributes
Single valued attributes contain one single
value.
For example:Adharno , Age
9
Stored attribute:
• An attribute whose value cannot be derived from
the values of other attributes is called a stored
attribute. For example, DOB
Derived attributes
• Can be computed from other attributes
Example: age given date_of_birth.
10
Relationships and Relationship Set
Relationship:
• A relationship relates two or more distinct entities with a specific
meaning.
For example: CUSTOMER ‘Jones’ has Loan ‘L-23’ ….
Relationship Set:
• Relationships of the same type are grouped or typed into a
relationship set / type.
For example: the ‘Borrower’ relationship type in which CUSTOMER
and Loan participate.
• The degree of a relationship type is the number of participating
entity sets.
12
Relationships
13
14
Degree of a Relationship Set
• Refers to number of entity sets that participate in a
relationship set.
• Relationship sets that involve two entity sets are
binary (or degree two). Generally, most relationship
sets in a database system are binary.
• Relationship sets may involve more than two entity
sets.
• Relationships between more than two entity sets are
rare. Most relationships are binary.
• Relationship types of degree 3 are called ternary and
of degree n are called n-ary
15
Mapping Cardinality Constraints
16
• Most useful in describing binary relationship sets.
❖ One to one
❖ One to many
❖ Many to one
❖ Many to many
17
a)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.
18
Many to one: An entity in A is associated with at most one entity in B, and
an entity in B is associated with any number of entities in A.
20
Basic E-R Notation
Symbol Meaning
ENTITY SET
RELATIONSHIP SET
ATTRIBUTE
KEY ATTRIBUTE
MULTIVALUED ATTRIBUTE
COMPOSITE ATTRIBUTE
DERIVED ATTRIBUTE
21
Entity Set with a multivalued attribute, derived attribute
& Primary Key
Primary Key
Multivalued:
Derived an employee can have
from date employed and current date more than one skill
Primary Key: An attribute or group of attributes that uniquely
identifies each row in a relation.
22
E-R Diagram With Composite, Multivalued, and Derived Attributes
● Rectangles represent entity sets.
● Diamonds represent relationship sets.
● Lines link attributes to entity sets and entity sets to relationship sets.
● Ellipses represent attributes
● Double ellipses represent multivalued attributes.
● Dashed ellipses denote derived attributes.
● Underline indicates primary key attribute.
23
E-R Diagrams
24
Relationship Sets with Attributes
25
E-R Diagram with a Ternary
Relationship
26
27
28
29
30
Optionality and Cardinality
Optionality expresses whether a
relationship is optional or
mandatory.
Cardinality is the maximum
number of relationships
Single stroke (I) indicates
relationship is mandatory.
minimum number of relationship
between each instance of
related entities are one.
(II) Indicates maximum no of
relationship is one.
Indicates many
relationship exist between
entities
(O) Indicated optional. Minimum
number of relationships between31
enties are zero
CARDINALITY RATIO
32
Weak Entity & Strong Entity Sets
• An entity set that does not have a primary key is referred to as a weak
entity set.
• The discriminator (or partial key) of a weak entity set is the set of
attributes that distinguishes among all the entities of a weak entity set.
• The primary key of a weak entity set is formed by the primary key of the
strong entity set on which the weak entity set is existence dependent,
plus the weak entity set’s discriminator.
33
Strong vs. Weak Entities, and
Identifying Relationships
• Strong entities:
– Exist independently of other types of entities
– Has its own unique identifier
– Represented with single-line rectangle
• Weak entity:
– Dependent on a strong entity…cannot exist on its own
– Does not have a unique identifier
– Represented with double-line rectangle
• Identifying relationship:
– Links strong entities to weak entities
– Represented with double line diamond
34
Identifying relationship
• We represent weak entity sets by double rectangles.
• We underline the discriminator of a weak entity set with
a dashed line.
payment_number – discriminator of the payment entity set
Primary key for payment – (loan_number, payment_number)
35
Identifying relationship
37
38
ERD for student database
39
ERD for Employee Salary database
40
41
ER Diagram for Company Database
42
43
44
45
Relationship types of degree
higher than two
Superclass and subclass
A superclass is an entity type that has one
or more distinct subgroups with unique
attributes.
The subgroups with unique attributes are
defined as subclasses
46
Generalization and Specialization Process
• Generalization is the process of
• defining general entity types
• from a set of specialized entity types
• by identifying their common
characteristics.
47
48
For example, the entity type PERSON in below fig is a
superclass that includes faculty, staff, and students as its
subclasses.
The superclass features only those attributes that are
common for all its subclasses.
For example, attributes of PERSON such as SSN, Name,
Address, and Email are shared by all its subgroups
regardless of an individual’s position as student, faculty, or
staff within the university.
50
Specialization is the process of
•defining one or more subclasses of a
superclass
•by identifying its distinguishing
characteristics.
51
Specialization-Example
52