DB Chapter2

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 63

Chapter - 2

CONCEPTUAL DATA MODELING AND


DATABASE DESIGN
Outline
Basic concepts of E-R model
The entity relationship(E-R) model is :
A high-level(conceptual) data model

It perceives the mini-world as a collection of basic objects


called entities.

It also contains the descriptions of entities called attributes and


the relationship between/among the entities

ER Diagram is a graphical representation of a Entity-


Relationship Model.
Cont’d…
E-R modeling is mainly used to create the conceptual
schema for the database from the collected system
specifications.
This process is called the conceptual design
The E-R model is DBMS independent
E/R Diagram notation
Cont’d…
Entity
An entity is an object that exists and which is distinguishable from
other objects.
Can be a person, a place, an object, an event, or a concept

Entity Representation in an E-R Diagram


Cont’d…
An entity type defines a collection of entities that have the same
attributes

An entity instance is a single item in this collection

An entity set is a set of entity instances

Example:
Entity type: STUDENT
Entity instance: Student with ID number AAU021
Entity set: Collection of all students
Attributes in ER diagram

Attributes of the STUDENT Entity Type


Cont’d…
A particular instance of an attribute is called a value.

For example, “Employee Id” and “Name” are the attributes of


the “EMPLOYEES” entity set; and “Jones” is one value of the
attribute “Name”.

The domain of an attribute is the collection of all possible


values an attribute can have. The domain of “Name” is a
character string
Cont’d…

Attributes can be classified as identifiers or descriptors.

Identifiers: more commonly called keys, uniquely identify an instance


of an entity.

Example: “Employee Id” uniquely identifies an employee entity from


the entity set.

Descriptor: describes a non-unique characteristic of an entity instance.

Example: “Name” is a descriptor for the “EMPLOYEES” entity set.


Types of attributes
Simple

Composite

single-valued

multi-valued

Stored and

Derived attributes
Simple vs composite attributes
Single-Valued VS Multi-Valued attributes

Single-valued attributes have a single value for an entity instance.

Examples: Dob, Reg. No

Multi-valued attributes, on the other hand, may have more than one
value for an entity instance

Denoted with a double-lined ellipse

Example

Languages: Stores the names of the languages that a student speak


Derived Attributes VS Stored

The value of a derived attribute can be determined by


analyzing other attributes.
Denoted with a dashed ellipse
Example:
Age: Can derived from the current date and the attribute Date
Of Birth
An attribute whose value cannot be derived from the values of
other attributes is called a stored attribute
Relationships

Relationships are associations between one or more entity


types.
A relationship type is represented by diamond connected to
relating entities by lines

A relationship should have a name , an optionality (optional or


mandatory) and a cardinality.

Examples: Customer “has” Account


Degree of a relationships

The degree of a relationship : is the number of entity types


that participate in a relationship.

There are 3 common relationships:

1. Unary (degree one)

2. Binary (degree two)

3. Ternary (degree three)


Cont’d…
Unary (degree 1) :An association between two instances of the same
entity type
R є E1 x E1
E.g. An employee supervises another employee
Binary Relationship

Binary (degree 2) – Most relationship sets in a DB System are binary .

An association between two different entity types

R є E1 x E2

E.g. Customer has bank Account


Ternary Relationship

An association among three different entity types

R є E1 x E2 x E3

E.g. A bank employee who has a specific job in a bank branch


INITIAL ER DIAGRAM FOR COMPANY
Structural constraints
Relationship types usually have certain constraints that limit the
possible combinations of entities that may participate in the
corresponding relationship set.

 These constraints are determined from the mini world situation


that the relationships represent.
Cont’d…
Cardinality ratio
The cardinality of a relationship defines the number of instances

of one entity type that can be associated with instances of

another entity type


The maximum cardinality of a relationship defines the
maximum number of instances of one entity type that can be
associated with instances of another entity type
Types of relationships
One –to one
One –to-many(vice versa)
Many –to -many

Relationship Types Based on Maximum Cardinality


Cont’d…
How do you know the maximum cardinality between two entity
types?

Questions:
Q1. Can an instance of X be associated with more than one
instance of Y?
Q2. Can an instance of Y be associated with more than one
instance of X?
The 2 questions above have 4 possible answers. Those answers
determine the type of maximum cardinalities
Cont’d…
Question 1 Question 2 Types of maximum cardinality
Yes Yes Many-to-Many
Yes No Many –to-One
No Yes One –to-Many
No No One –to-One
One to One Relationship
An entity in X is associated with at most one entity in Y
and vice-versa.

Example: each passenger has his own Ticket


One to Many Relationship
 An entity in X is associated with any number of entities in Y.
But an entity in Y can associate with at most one entity in X
 E.g. A department contains many employees who work under
it
Many to One Relationship
An entity in X is associated with at most one entity in Y. But an
entity in Y can be associated with any number of entities in X.

 E.g. Student and Guide


Many to Many Relationship

An entity in X is associated with any number(zero or


more) of entities in Y ,and an entity in Y is associated
with any number (zero or more ) of entities in X
Relationship Cardinalities
Mandatory Cardinalities: The entity must participate in another
entity.(crow’s foot notation)

Optional Cardinalities: The entity has the option to participate in


another entity.
Cont’d…

Relation types based on minimum cardinality


Crow’s foot notation
Participation constraint
Participation constraint is defined as the minimum number of
instances of one entity type that must be associated with each
instance of another entity type
There are 2 types of participation constraints:

1.Total participation

2.Partial participation
Total Participation
In total participation , each entity in the entity set occurs in at
least one relationship in the relationship set
The example below shows that the participation of the entity set
Department Manages is total . This is because every department
must have a manager .
Partial participation

In partial participation , some entities (not all entities) in the entity set occurs
in the relationship in the relationship set.
Example : EMPLOYEE in the MANAGES relationship type. we do not expect
every employee to manage a department, so the participation of EMPLOYEE in
the MANAGES relationship type is partial(some or "part of the set of" employee
entities are related to a department entity via MANAGES, but not necessarily
all) .
Cont’d…
A strong entity type exists independent of other entity types. They have their
own primary keys.
A weak entity type is an entity type that doesn’t have a primary key of its own.
It depends on
another entity type called the owner or identifying entity type to be uniquely
identified
It needs Foreign keys in conjunction with its attributes to create a primary key
A weak entity type always has a total participation constraint with respect to
its identifying relationship.
Cont’d…
Cont’d…
From the previous slide we can see that Dependent is a weak
entity type. It is not an object of interest to be stored in the
database but it should be stored because of the existence of
another entity type – the Employee – which it is related with
Employee is the owner or the identifying entity type
Dependent is described by the dependent’s first name , last name and birth
date
It is related with the owner entity type via the identifying relationship type
HAS
Cont’d…

Exercise
A. Construct an E-R diagram for a hospital with a set of patients and a set of
medical doctors.
Associate with each patient a log of the various tests and examinations
conducted.

Assignment
B. Construct appropriate tables for the above ER Diagram
 Construct full ER diagram for Company
Enhanced entity relationship(EER)
Introduction
 Since the late 1970 there has been an increase in the emergence of
new database applications, such as GIS, Multimedia databases,
Mobile databases ,etc. with more demanding requirements

Basic concepts of the ER model are not sufficient to represent the


requirements of the newer, more complex applications
Cont’d…
To represent these requirements additional ‘semantic’
modeling concepts are needed.

These semantic concepts are incorporated into the original ER


model and became Enhanced Entity-Relationship (EER) model

EER diagrams are similar to the class diagrams used in the OO


model.
Concepts of EER
The EER model includes all the concepts used in the ER model:
◦ Entity types
◦ Attributes
◦ Relationship types

In addition, the EER model includes the following concepts,


which come from the OO model:
◦ Super class/subclass relationship

◦ Attributes inheritance

◦ Specialization and Generalization


Cont’d…
Super class: is an entity type that includes distinct subgroups
with their own unique attributes that should be represented in
the model.
Subclass: is an entity type that is a member of the super class
with its own distinct role. Or it is any subgroup of the Super
class.
Cont’d…
The relationship between a super class and any of its subclasses
is called the super class/subclass relationship.
Attribute inheritance: an entity in a subclass may posses the
attributes of the super class and other attributes specific to itself.
Super class and Subclass Relationships

An entity type may have additional meaningful sub grouping of


its entities.

Example

Employee may be further grouped into:


SECRETARY,ENGINEER,MANAGER,TECHNICHIAN,SALARIED_EMP
LOYEE,HOURLY_EMPLOYEE

Every instance in a subclass is a member of super class and


shares its attributes
Super class/Subclass relationship notation

.
Super class/Subclass relationship example
University Example of Super class/Subclass
Generalization and Specialization

Specialization and generalization are two basic concepts


that help us to recognize possibilities that are enabled by
Super class/Subclass models in the real world.
They serve as conceptual models for development of
Super class/Subclass relationships
Cont’d…
Specialization and Generalization are inverses of each other.

Specialization => Deriving subclasses from a super class

Generalization => Taking common attributes from the

Super class
Specialization
A Specialization is the process of defining a set of subclasses of a super class by
identifying their distinguishing attributes.

The specialization of an entity type allows us to do the


following:
Define a set of subclasses of an entity type

Establish additional attributes with subclasses

Establish additional relationship types between some subclasses and


other entity types or other subclasses.
Specialization - example
.
Generalization
Generalization is the process of defining a super class from two
or more subclasses by identifying common attributes of those
subclasses.
Generalization can be considered as the reverse of specialization.
Example
We can view EMPLOYEE as a generalization of SECRETARY,
TECHNICIAN, and ENGINEER
Cont’d…
Entities before Generalization
Cont’d…

Super classes and subclasses after generalization


Alternative notations
Alternative notations
UML Class Diagrams: a class (similar to an entity type in ER) is
displayed as a box includes three sections:

The top section gives the class name (similar to entity type name);

the middle section includes the attributes;

the last section includes operations that can be applied to individual


objects (similar to individual entities in an entity set) of the class.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy