Unit2 CP 1 DBMS

Download as pdf or txt
Download as pdf or txt
You are on page 1of 52

Unit - II

Data Modelling Using the


Entity-Relationship Model

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

• Entities have attributes


– Example: people have names and addresses

• An entity set is a set of entities of the


same type that share the same properties.
– Example: set of all persons, companies, trees,
holidays 3
Definitions
Entities and Attributes:
– Entities are specific objects or things in the mini-world that are
represented in the database.
Example: specific person, company, student, event, plant
– Attributes are properties used to describe an entity. i.e, Entities have
attributes.
Example: an EMPLOYEE entity may have a Name, SSN, Address,
Designation, Salary.
A specific entity will have a value for each of its attributes. For
example a specific employee entity may have Name='John Smith',
SSN='123456789', Address ='731, Houston, TX',
BirthDate='09-JAN-75‘
Each attribute has a value set (or data type) associated with it – e.g.
integer, string, …
– Entity set is a set of entities of the same type that share the same
properties.
Example: set of all persons, companies, trees, holidays
4
Entity Sets customer and loan
customer customer customer customer loan
amount
id name street city no.

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 )

Domain – the set of permitted values for each attribute.


There exists a domain or range of values that can be
assigned to attributes.
For example, a student's name cannot be a numeric value. It
has to be alphabetic. A student's age cannot be negative,
etc.
6
Name 4 types of attributes
• : Attribute types: Simple attribute, composite attributes
• Simple attributes have atomic values,
which cannot be divided further.
• For example, student's phone-number is
an atomic value of 10 digits.
composite attributes (attributes are divided into
subparts). Example: Name

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

Multivalued attributes may contain more than


one values.
For example, a person can have more than one
phone numbers, EmailId ,Employee dependant
(1,or 2 or 3)

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.

• Define entity and relationship (2m)


11
Entity-set and Keys

• Key is an attribute or collection of


attributes that uniquely identifies an
entity among entity set.
• For example, RegNo of a student makes
her/him identifiable among students.
• Primary Key: An attribute or group of
attributes that uniquely identifies each
row in a relation.

12
Relationships

Relationship Set borrower

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

• Cardinality defines the number of entities in


one entity set which can be associated to
the number of entities of other set via
relationship set.
• Express the number of entities to which another
entity can be associated via a relationship set.

• Explain cardinality ratio constraint of


relationships-5m

16
• Most useful in describing binary relationship sets.

• For a binary relationship set the mapping cardinality


must be one of the following types:

❖ 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.

b)One to many: An entity in A is associated with any number of entities in


B. An entity in B, however can be 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.

Many to many: An entity in A is associated with any number of entities in


B. and n entity in B, is associated with any number of entities in A.
19
Describe different types of notations used
in ER-diagram 5m

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

We allow at most one arrow out of a ternary (or greater degree)


relationship to indicate a cardinality constraint
E.g. an arrow from works_on to job indicates each employee works on at
most one job at any branch.

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.

• An entity set which is capable of having a primary key is referred to as a


Strong entity set.

• The existence of a weak entity set depends on the existence of a Strong


entity set

– Identifying weak entity set is represented with double-line rectangle.


– Identifying relationship is the relationship between Strong and weak
entity sets and it is represented by double diamond.

• 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

Strong entity Identifying relationship Weak entity 36


Roles
• Entity sets of a relationship need not be distinct
• The labels “manager” and “worker” are called roles;
they specify how employee entities interact via the
works_for relationship set.
• Roles are indicated in E-R diagrams by labeling the
lines that connect diamonds to rectangles.

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.

The subgroups with unique attributes are defined as


subclasses.

The PERSON superclass thus has three subclasses:


STUDENT, STAFF, and FACULTY.
A subclass entity type STUDENT has attributes of its
superclass along with its own attributes such as Major,
49
GPA, and Class that uniquely identify the subclass.
Generalization-Example

50
Specialization is the process of
•defining one or more subclasses of a
superclass
•by identifying its distinguishing
characteristics.

It starts with the general entity (superclass)


and forms specialized entity types
(subclasses) based on specialized attributes
or relationships specific to a subclass.

51
Specialization-Example

52

You might also like