You are on page 1of 48

Chapter-Three

DATABASE MODELING

fundamental of database system CS@SLU


Outlines
2

√ Overview Of Database Model


√ Developing An E-R Diagram
√ Entity Types And Key Attributes
√ Initial Conceptual Design Of The
Database System
√ Relationship Degree

fundamental of database system CS@SLU


Categories of Data Models
3

Conceptual (high-level, semantic) data models:


 Provide concepts that are close to the way many users perceive
data.
 (Also called entity-based or object-based data models.)
Physical (low-level, internal) data models:
 Provide concepts that describe details of how data is stored in
the computer.
 These are usually specified in an ad-hoc manner through DBMS
design and administration manuals
Implementation (representational) data models:
 Provide concepts that fall between the above two, used by many
commercial DBMS implementations
 (e.g. relational data models used in many commercial systems).
fundamental of database system CS@SLU
Cont…
4
Within the history of database systems we have :-
The first generation data models
 Hierarchical Model
 Network Model
The second generation data models
 Relational Model
The third generation data models
 Object Oriented Data Models

fundamental of database system CS@SLU


Cont…
5

Hierarchical Data Model


 The simplest data model
 Record type is referred to as node or segment
 The top node is the root node
 Nodes are arranged in a hierarchical structure as sort of upside-
down tree
 A parent node can have more than one child node
 A child node can only have one parent node
 The relationship between parent and child is one-to-many
Relation is established by creating physical link between stored
records

fundamental of database system CS@SLU


Cont…
6

fundamental of database system CS@SLU


Cont…
7

Network Data Model


 Allows record types to have more than one parent unlike
hierarchical model
 It doesn't allow many to many relationship between entities
 Like hierarchical model network model is a collection of
physically linked records.

fundamental of database system CS@SLU


Cont…
8
Relational Data Model
 Viewed as a collection of tables
called “Relations” equivalent
to collection of record types
 Relation: Two dimensional
table
 Stores information or data in the
form of tables -->rows and
columns
 A row of the table is called
tuple--> equivalent to record
 A column of a table is called
attribute--> equivalent to
fields

fundamental of database system CS@SLU


Cont…
9

The Object-Oriented Model


The object-oriented model is based on a collection of objects, like the
E-R model.
 An object contains values stored in instance variables within the
object.
 An object also contains bodies of code that operate on the
object.
 These bodies of code are called methods.
 Objects that contain the same types of values and the same
methods are grouped into classes.
 A class may be viewed as a type definition for objects.

fundamental of database system CS@SLU


Developing an E-R Diagram
10

 Designing conceptual model for the database is not a


linear process but an iterative activity where the
design is refined again and again.
To identify :-
 Entities
 Attributes
 Relationships
 Constraints on the data

fundamental of database system CS@SLU


Cont...
11

Entity
 It is simply specific object or things in the real world to
represent database.
Example: employee, project, department, book, computer
 Entity is represented by rectangular shapes contained an entity
name inside it.

fundamental of database system CS@SLU


Cont...
12

Attributes
 Attributes is simply is the characteristics or behaviours that
describe an entity.
 On the above example an employee entity has an attributes
like employee name, salary, age and mobile numbers.
 A specific entity will have a value for each of its attributes.
 For example a specific employee entity may have Name='John
Smith', salary=‘20000', age ='31’, m=‘+251******** ‘
 Each attribute has a value set (or data type) associated with it –
e.g. integer, string, sub range, enumerated type, …

fundamental of database system CS@SLU


Cont...
13

Attributes can be:


Single :means each entity have single or unique value.
Example: idno, sex
Composite:The attribute may be composed of several
components. example:
 composite attributes are shown between set braces ().
o name(firstname, middlename, lastname)
o account(faceebook, email)
Multi-valued: An entity may have multiple values for that
attribute.
example, Color of a CAR or PreviousDegrees of a STUDENT,
TELL
 Multivalued attributes are shown between set braces {}.
fundamental of database system CS@SLU
Cont...
14

Derived Attributes: A situation where one attributes derived


from another attributes.
(i.e In some cases, two (or more) attribute values are related.
example, the Age and Birth_date attributes of a person.
 For a particular person entity, the value of Age can be
determined from the current(today’s) date and the value of that
person’s Birth_date. The Age attribute is hence a derived
attribute and is said to be derivable from the Birth_date
attribute,

fundamental of database system CS@SLU


Cont…
15

 Another example consider course and gpa so in this case gpa is


derived from the mark or point of each subject offered in the
course.
 Attributes is represented by oval shapes and it is connected to
the entity by lines.

fundamental of database system CS@SLU


Cont...
16

 Derived attributes indicated by dotted line (….).

 Primary key is underlined.

Relationships
are represented by DIAMOND shaped symbols.
There are two types relationships.
 Weak Relationship is a relationship between Weak and Strong Entities.
 Strong Relationship is a relationship between two strong Entities
fundamental of database system CS@SLU
Cont...
17

 if a relationship have it is own attributes it simply known as


associative entity.it is represented by diamond shape enclosed
by rectangular.

fundamental of database system CS@SLU


Entity Types and Key Attributes
18

 Entities with the same basic attributes are grouped or typed


into an entity type.
 For example, the EMPLOYEE entity type or the PROJECT
entity type.
 An entity type may have more than one key.
 For example, the CAR entity type may have two keys:
 VehicleIdentificationNumber (popularly called VIN) and
 VehicleTagNumber (Number, State), also known as
license_plate number
 If each entity type has a collection of entities stored in
database the are called entity set.

fundamental of database system CS@SLU


Key attributes
19

An attribute of an entity type for which each entity


must have a unique value is called a key attribute of
the entity type.
 For example, SSN of EMPLOYEE.
Key attribute
 Uniqueness property must hold for every entity set of the
entity type
A key attribute may be composite.
 For example, VehicleTagNumber is a key of the CAR entity
type with components (Number, State).

fundamental of database system CS@SLU


ER Diagrams, Naming Conventions, and Design Issues
20

fundamental of database system CS@SLU


How to Draw ER Diagrams
21

 Identify all the entities in the system. An entity should appear


only once in a particular diagram. Create rectangles for all
entities and name them properly.
 Identify relationships between entities. Connect them using a
line and add a diamond in the middle describing the
relationship.
 Add attributes for entities. Give meaningful attribute names so
they can be understood easily.

fundamental of database system CS@SLU


Initial Conceptual Design of the Database system
22

 Example 1: Build an ER Diagram for the following information:


A student record management system will have the following
two basic data object categories with their own features or
properties:
 Students will have an Id, Name, Dept, Age, GPA and Course
will have an Id, Name, Credit Hours\2019SZA\M2…………4.
 Whenever a student enrol in a course in a specific Academic Year
and Semester, the Student will have a grade for the course.

fundamental of database system CS@SLU


Cont…
23

So on the above example we have student and course entity, Id, Name, Dept,
Age, GPA is attributes for student entity, Id, Name, Credit Hours\2019SZA\
M2…………4.
Is attributes for course entity, enrol is types of relationships entitled between
student and course. this is the ER diagram for the above informations.

fundamental of database system CS@SLU


Cont…
24

Exercise 1
Exercise: Build an ER Diagram for the following information:
A Personnel record management system will have the following two basic data object
categories with their own features or properties:
 Employee will have an Id, Name, DoB, Age, Tel and
 Department will have an Id, Name, Location
Whenever an Employee is assigned in one Department, the duration of his stay in the
respective department should be registered.
Exercise 2
Build an ER Diagram for the following information:
 Patients
 Name, Address, Phone #, Age
 Drugs
 Name, Manufacturer , Expiration Date
 Patients are prescribed drugs
 Dosage, # Days
fundamental of database system CS@SLU
Relationship Types, Relationship Sets, and Structural
Constraint
25

Relationship
 When an attribute of one entity type refers to another entity type.
 Represent references as relationships not attributes
 A relationship type R among n entity types E1, E2, ..., En
 defines a set of associations or a relationship set among entities
from these entity types.
 Relationship instances ri
 Each ri associates n individual entities (e1,e2, ..., en)

 Each entity ej in ri is a member of entity set Ej


 For example consider the relationship work for between two entity (employee
and department) which implies each employee entity work for department.
 Each relationship instance in the relationship set WORKS_FOR associates
one EMPLOYEE entity and one DEPARTMENT entity.
fundamental of database system CS@SLU
26

o In the miniworld represented by Figure, employees e1, e3, and e6 work


for department d1; employees e2 and e4 work for department d2; and
employees e5 and e7 work for department d3

Some instances in the


WORKS_FOR relationship set,
which represents a
relationship type
WORKS_FOR between
EMPLOYEE and
DEPARTMENT.

fundamental of database system CS@SLU


Relationship Degree
27

 It is simply the number of entity types which took part in the


entity relationship is called the degree of relationships.
 There are three different types of degree of relationships, they
are as follows −
 Unary relationship
 Binary relationship
 Ternary relationship
 Example on the above work for relationships is participants
entities of degree two.
 Relationships as attributes
 Think of a binary relationship type in terms of attributes.

fundamental of database system CS@SLU


Unary relationships
28

Unary relationship: it is the relationship between the instances


of a single entity type. It is also called a recursive relationship.
Example
 A person is married is a one-to-one relationship between the
instances of Person entity type of unary relationship.

fundamental of database system CS@SLU


Binary Relationship
29

Binary(degree of 2)
 A relationship type of degree two is called binary.
 Which means the associative relationships between two entity.
 R єE1 x E2
 E.g. Customer has bank Account

Binary relationships may be


1 to 1, 1 to m, m to n

fundamental of database system CS@SLU


Ternary relationships
30

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

fundamental of database system CS@SLU


Constraints on Binary Relationship
Types
31

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 miniworld situation that the
relationships represent.
 Specifies the number of relationship instances an entity can
participate in.
 Specifies lower and uper bounds on the number of relationships
each entity can participate in.
 there are two main types of binary relationships constraints.
 cardinality ratio
 participation

fundamental of database system CS@SLU


Constraints on Binary Relationship Types
32
Cardinality Ratios for Binary Relationships: The cardinality ratio
for a binary relationship specifies the maximum number of
relationship instances that an entity can participate in.
 For example, in the WORKS_FOR binary relationship type,
DEPARTMENT:EMPLOYEE is of cardinality ratio 1:N,meaning
that each department can be related to (that is,employees) any
number of employees, but an employee can be related to (work for)
only one department.
The possible cardinality ratios for binary relationship types are 1:1,
1:N, N:1, and M:N.
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.
fundamental of database system CS@SLU
Types of cardinality ratio/constraints
relationships
33

One-to-one relationship: If the relationship between A and B


satisfies the one-to-one mapping constraint from A to B, then:
an entity in A is related to at most one entity in B,
an entity in B is related to at most one entity in A
E.g. Each passenger has his own Ticket

 One -2-Many relationship: An entity in X is associated with any


number(zero or more) 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.

fundamental of database system CS@SLU


Types of cardinality ratio/constraints
relationships
34

Many-2-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.
example1: student register in course.

example2: instructor teaches course

fundamental of database system CS@SLU


Constraints on Binary Relationship Types
35

Participation constraint of a relationship


• specifies whether the existence of an entity depends on its
being related to another entity via the relationship type.
• This constraint specifies the minimum number of relationship
instances that each entity can participate in.
There are two distinct participation constraints with this
respect, namely:-
 Total Participation and
 Partial Participation

fundamental of database system CS@SLU


Constraints on Binary Relationship Types
36

 Total participation constraints require the participation of every entity in


the relationship.
It is displayed by a double line.
 partial participation , some entities (not all entities) in the entity set
occurs in the relationship in the relationship set.
 • Partial participation constraints(displayed by a single
line).
 Participation of EMPLOYEE in “manages” relationship with
DEPARTMENT, is partial participation since not all employees are
managers.
 Participation of DEPARTMENT in “Manages” relationship with
EMPLOYEE is total since every department should have a manager.

fundamental of database system CS@SLU


Enhanced entity-relationship (EER)
37

 Enhanced entity-relationship (EER) diagrams are basically


an expanded upon version of ER diagrams.
 EER models are helpful tools for designing databases with
high-level models.
 We use when basic concepts of the ER model are not
sufficient to represent the requirements of the newer, more
complex applications

Fundamentals of Database Systems 04/01/2024


Enhanced entity-relationship (EER)…
38

 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:
 Superclass/subclass relationships
 Attribute inheritance
 Specialization
 Generalization

Fundamentals of Database Systems 04/01/2024


Enhanced entity-relationship (EER)…
39

 Superclass: is an entity type that includes distinct


subgroups with their own unique attributes that should be
represented in the model
 Subclass: entity type that member of the superclass with its
own distinct role. Or it is any subgroup of the Superclass.
 Attribute inheritance: an entity in a subclass may posses
the attributes of the superclass and other attributes specific
to itself
 The relationship between a superclass and any of its
subclasses is called the superclass/subclass relationship.

Fundamentals of Database Systems 04/01/2024


Superclass and Subclass Relationships…
40

Fundamentals of Database Systems 04/01/2024


Superclass and Subclass Relationships>>Example
41

Fundamentals of Database Systems 04/01/2024


Inheritance
42

 Inheritance is an important feature of Generalization and Specialization.


 It allows lower-level entities to inherit the attributes of higher-level entities.
 The details of entities are generally hidden from the user; this process known
as abstraction.

the attributes of a Person


class such as name, age,
and gender can be
inherited by lower-level
entities such as Student
or Teacher.

Fundamentals of Database Systems 04/01/2024


Generalization and Specialization
43

Generalization
 a number of entities are brought together into one generalized entity
based on their similar characteristics.
 Generalization is taking common attributes from the subclasses and
deriving a common superclass
Specialization
 is the opposite of generalization. In specialization, a group of entities is
divided into sub-groups based on their characteristics.
 Specialization=> Deriving subclasses from a superclass

 They serve as conceptual models for development of Superclass/Subclass


relationships
 Specialization and Generalization are inverses of each other

Fundamentals of Database Systems 04/01/2024


Specialization
44

 A specialization is the process of defining a set of sub


classes of a superclass 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.

Fundamentals of Database Systems 04/01/2024


Specialization>>Example
45

Fundamentals of Database Systems 04/01/2024


Specialization>>Example…
46

Entities Before Specialization

Superclass and Subclass Entities


After Specialization

Fundamentals of Database Systems 04/01/2024


Specialization>>Example…
47

 The following Figure shows an example of some instances


of the specialization of the superclass EMPLOYEE into the
set of subclasses {SECRETARY, ENGINEER,
TECHNICIAN}

Fundamentals of Database Systems 04/01/2024


Cont… Chapter-Four
48

Thank you
?

fundamental of database system CS@SLU

You might also like