0% found this document useful (0 votes)
16 views54 pages

Lec 5 - DBMS-2024

The document outlines the concepts and processes involved in database design, focusing on the Entity-Relationship (ER) model, including entities, attributes, and relationships. It provides an example of a COMPANY database schema, detailing the entities involved such as EMPLOYEE, DEPARTMENT, PROJECT, and DEPENDENT, along with their attributes and relationships. Additionally, it discusses ER diagrams and their notation, highlighting the importance of these tools in designing and debugging relational databases.

Uploaded by

bsse23018
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views54 pages

Lec 5 - DBMS-2024

The document outlines the concepts and processes involved in database design, focusing on the Entity-Relationship (ER) model, including entities, attributes, and relationships. It provides an example of a COMPANY database schema, detailing the entities involved such as EMPLOYEE, DEPARTMENT, PROJECT, and DEPENDENT, along with their attributes and relationships. Additionally, it discusses ER diagrams and their notation, highlighting the importance of these tools in designing and debugging relational databases.

Uploaded by

bsse23018
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

Undergraduate

Database Management
Systems

Lecture 5

Hamza Shaukat
[email protected]

Information Technology University (ITU)


Faculty of Engineering
Chapter Outline

Overview of Database Design Process


Example Database Application (COMPANY)
ER Model Concepts
▪ Entities and Attributes
▪ Entity Types, Value Sets, and Key Attributes
▪ Relationships and Relationship Types
▪ Weak Entity Types
▪ Roles and Attributes in Relationship Types
ER Diagrams - Notation
ER Diagram for COMPANY Schema
Alternative Notations – UML class diagrams, others

Slide 3- 2

Information Technology University (ITU)


Faculty of Engineering
Chapter Summary

ER Model Concepts: Entities, attributes, relationships


Constraints in the ER model
Using ER in step-by-step conceptual schema design for the
COMPANY database
ER Diagrams - Notation
Alternative Notations – UML class diagrams, others

Information Technology University (ITU)


Faculty of Engineering
Overview of Database Design Process
Two main activities:
▪ Database design
▪ Applications design
Focus in this chapter on database design
▪ To design the conceptual schema for a database
application
Applications design focuses on the programs and
interfaces that access the database
▪ Generally considered part of software engineering

Information Technology University (ITU)


Faculty of Engineering
Overview of Database Design Process

Information Technology University (ITU)


Faculty of Engineering
ER Diagram

An Entity Relationship (ER) Diagram is a type of flowchart that illustrates how


“entities” such as people, objects or concepts relate to each other within a
system. ER Diagrams are most often used to design or debug relational
databases in the fields of software engineering, business information
systems, education and research. Also known as ERDs or ER Models,
they use a defined set of symbols such as rectangles, diamonds, ovals and
connecting lines to depict the interconnectedness of entities, relationships
and their attributes.

Information Technology University (ITU)


Faculty of Engineering
ER Model Concepts

Entities and Attributes


▪ Entities are specific objects or things in the mini-world
that are represented in the database.
– For example the EMPLOYEE John Smith, the Research
DEPARTMENT, the ProductX PROJECT
▪ Attributes are properties used to describe an entity.
– For example an EMPLOYEE entity may have the attributes
Name, SSN, Address, Sex, BirthDate
▪ 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,
Fondren, Houston, TX', Sex='M', BirthDate='09-JAN-55‘
▪ Each attribute has a value set (or data type) associated
with it – e.g. integer, string, subrange, enumerated type.

Information Technology University (ITU)


Faculty of Engineering
Example of Entities

Information Technology University (ITU)


Faculty of Engineering
Entity Type

It refers to the category that a particular entity belongs to.

Information Technology University (ITU)


Faculty of Engineering
Entity Set

An entity set is a collection or set of all entities of a particular entity


type at any point in time. The type of all the entities should be the
same.

10

Information Technology University (ITU)


Faculty of Engineering
Example

11

Information Technology University (ITU)


Faculty of Engineering
Types of Attributes (1)

Simple
▪ Each entity has a single atomic value for the attribute. For
example, SSN or Sex.
Composite
▪ The attribute may be composed of several components. For
example:
– Address(Apt#, House#, Street, City, State, ZipCode, Country),
or
– Name(FirstName, MiddleName, LastName).
– Composition may form a hierarchy where some
components are themselves composite.
Multi-valued
▪ An entity may have multiple values for that attribute. For
example, Color of a CAR or PreviousDegrees of a
STUDENT.
– Denoted as {Color} or {PreviousDegrees}.

12

Information Technology University (ITU)


Faculty of Engineering
Entity

13

Information Technology University (ITU)


Faculty of Engineering
Example of a composite attribute

14

Information Technology University (ITU)


Faculty of Engineering
Multi Valued Example

15

Information Technology University (ITU)


Faculty of Engineering
Strong and Weak Entity

Strong Entity is independent of any other entity in the schema


Example – A student entity can exist without needing any other entity
in the schema or a course entity can exist without needing any
other entity in the schema

Weak Enitity is an entity that does not have a key attribute


A weak entity must participate in an identifying relationship type with
an owner or identifying entity type
Entities are identified by the combination of:
▪ A partial key of the weak entity type
▪ The particular entity they are related to in the identifying entity
type

16

Information Technology University (ITU)


Faculty of Engineering
Summary of notation for ER diagrams

17

Information Technology University (ITU)


Faculty of Engineering
Example

18

Information Technology University (ITU)


Faculty of Engineering
Example

19

Information Technology University (ITU)


Faculty of Engineering
Displaying an Entity type

In ER diagrams, an entity type is displayed in a rectangular


box
Attributes are displayed in ovals
▪ Each attribute is connected to its entity type
▪ Components of a composite attribute are connected
to the oval representing the composite attribute
▪ Each key attribute is underlined
▪ Multivalued attributes displayed in double ovals
See CAR example on next slide

20

Information Technology University (ITU)


Faculty of Engineering
Example

21

Information Technology University (ITU)


Faculty of Engineering
Entity Type CAR with two keys and a corresponding Entity
Set

22

Information Technology University (ITU)


Faculty of Engineering
Example COMPANY Database

We need to create a database schema design based on


the following (simplified) requirements of the
COMPANY Database:
▪ The company is organized into DEPARTMENTs.
Each department has a name, number and an
employee who manages the department. We keep
track of the start date of the department manager. A
department may have several locations.
▪ Each department controls a number of PROJECTs.
Each project has a unique name, unique number
and is located at a single location.

23

Information Technology University (ITU)


Faculty of Engineering
Example COMPANY Database (Contd.)

▪ We store each EMPLOYEE’s social security number,


address, salary, sex, and birthdate.
– Each employee works for one department but may work on
several projects.
– We keep track of the number of hours per week that an
employee currently works on each project.
– We also keep track of the direct supervisor of each
employee.
▪ Each employee may have a number of
DEPENDENTs.
– For each dependent, we keep track of their name, sex,
birthdate, and relationship to the employee.

24

Information Technology University (ITU)


Faculty of Engineering
Initial Design of Entity Types for the COMPANY
Database Schema
Based on the requirements, we can identify four initial entity
types in the COMPANY database:
▪ DEPARTMENT
▪ PROJECT
▪ EMPLOYEE
▪ DEPENDENT
Their initial design is shown on the following slide
The initial attributes shown are derived from the requirements
description

25

Information Technology University (ITU)


Faculty of Engineering
Initial Design of Entity Types: EMPLOYEE, DEPARTMENT, PROJECT,
DEPENDENT

26

Information Technology University (ITU)


Faculty of Engineering
Refining the initial design by introducing relationships

The initial design is typically not complete


Some aspects in the requirements will be represented as
relationships
ER model has three main concepts:
▪ Entities (and their entity types and entity sets)
▪ Attributes (simple, composite, multivalued)
▪ Relationships (and their relationship types and relationship
sets)
We introduce relationship concepts next

27

Information Technology University (ITU)


Faculty of Engineering
Relationships and Relationship Types (1)
A relationship relates two or more distinct entities with a
specific meaning.
▪ For example, EMPLOYEE John Smith works on the
ProductX PROJECT, or EMPLOYEE Franklin Wong
manages the Research DEPARTMENT.
Relationships of the same type are grouped or typed into a
relationship type.
▪ For example, the WORKS_ON relationship type in
which EMPLOYEEs and PROJECTs participate, or
the MANAGES relationship type in which
EMPLOYEEs and DEPARTMENTs participate.
The degree of a relationship type is the number of
participating entity types.
▪ Both MANAGES and WORKS_ON are binary
relationships.
28

Information Technology University (ITU)


Faculty of Engineering
Relationship Types

Degree of a Relationship Set


The number of different entity sets participating in a relationship set is called
the degree of a relationship set.
Unary Relationship: When there is only ONE entity set participating in a
relation, the relationship is called a unary relationship. For example, one
person is married to only one person.

29

Information Technology University (ITU)


Faculty of Engineering
Relationship Types

Binary Relationship: When there are TWO entities set participating in a


relationship, the relationship is called a binary relationship. For example, a
Student is enrolled in a Course.

30

Information Technology University (ITU)


Faculty of Engineering
Relationship Types

A Ternary relationship is the one that involves three entities

31

Information Technology University (ITU)


Faculty of Engineering
Participation Constraints

32

Information Technology University (ITU)


Faculty of Engineering
Total Participation

It specifies that each entity in the entity set must compulsorily participate in at
least one relationship instance in that relationship set.
That is why, it is also called as mandatory participation.
Total participation is represented using a double line between the entity set
and relationship set.

33

Information Technology University (ITU)


Faculty of Engineering
Partial Participation

It specifies that each entity in the entity set may or may not participate in the
relationship instance in that relationship set.
That is why, it is also called as optional participation.
Partial participation is represented using a single line between the entity set
and relationship set.

34

Information Technology University (ITU)


Faculty of Engineering
Cardinality

Cardinality represents the number of times an entity of an


entity set participates in a relationship set. Or we can
say that the cardinality of a relationship is the number of
tuples (rows) in a relationship. Types of cardinality in
between tables are:

1. one-to-one
2. one-to-many
3. many-to-one
4. many-to-many

35

Information Technology University (ITU)


Faculty of Engineering
One to One

One-to-one: In this type of cardinality mapping, an entity in A is connected to at


most one entity in B. Or we can say that a unit or item in B is connected to
at most one unit or item in A.

36

Information Technology University (ITU)


Faculty of Engineering
One to Many

One-to-many: In this type of cardinality mapping, an entity in A is associated


with any number of entities in B. Or we can say that one unit or item in B
can be connected to at most one unit or item in A.

37

Information Technology University (ITU)


Faculty of Engineering
Many to One

Many-to-one: In this type of cardinality mapping, an entity in A is connected to


at most one entity in B. Or we can say a unit or item in B can be
associated with any number (zero or more) of entities or items in A.

38

Information Technology University (ITU)


Faculty of Engineering
Many to Many

Many-to-many: In this type of cardinality mapping, an entity in A is associated


with any number of entities in B, and an entity in B is associated with any
number of entities in A.

39

Information Technology University (ITU)


Faculty of Engineering
Example COMPANY Database

We need to create a database schema design based on


the following (simplified) requirements of the
COMPANY Database:
▪ The company is organized into DEPARTMENTs.
Each department has a name, number and an
employee who manages the department. We keep
track of the start date of the department manager. A
department may have several locations.
▪ Each department controls a number of PROJECTs.
Each project has a unique name, unique number
and is located at a single location.

40

Information Technology University (ITU)


Faculty of Engineering
Example COMPANY Database (Contd.)

▪ We store each EMPLOYEE’s social security number,


address, salary, sex, and birthdate.
– Each employee works for one department but may work on
several projects.
– We keep track of the number of hours per week that an
employee currently works on each project.
– We also keep track of the direct supervisor of each
employee.
▪ Each employee may have a number of
DEPENDENTs.
– For each dependent, we keep track of their name, sex,
birthdate, and relationship to the employee.

41

Information Technology University (ITU)


Faculty of Engineering
Refining the COMPANY database schema by introducing
relationships

By examining the requirements, six relationship types are


identified
All are binary relationships( degree 2)
Listed below with their participating entity types:
▪ WORKS_FOR (between EMPLOYEE, DEPARTMENT)
▪ MANAGES (also between EMPLOYEE, DEPARTMENT)
▪ CONTROLS (between DEPARTMENT, PROJECT)
▪ WORKS_ON (between EMPLOYEE, PROJECT)
▪ SUPERVISION (between EMPLOYEE (as subordinate),
EMPLOYEE (as supervisor))
▪ DEPENDENTS_OF (between EMPLOYEE,
DEPENDENT)
Slide 3- 42

Information Technology University (ITU)


Faculty of Engineering
Relationship instances of the WORKS_FOR -- relationship between
EMPLOYEE and DEPARTMENT

Slide 3- 43

Information Technology University (ITU)


Faculty of Engineering
Relationship instances of the -- WORKS_ON relationship between
EMPLOYEE and PROJECT

Slide 3- 44

Information Technology University (ITU)


Faculty of Engineering
ER DIAGRAM – Relationship Types are:
WORKS_FOR, MANAGES, WORKS_ON, CONTROLS, SUPERVISION,
DEPENDENTS_OF

Slide 3- 45

Information Technology University (ITU)


Faculty of Engineering
Example

Slide 3- 46

Information Technology University (ITU)


Faculty of Engineering
Example

Slide 3- 47

Information Technology University (ITU)


Faculty of Engineering
Example

Slide 3- 48

Information Technology University (ITU)


Faculty of Engineering
Example

Slide 3- 49

Information Technology University (ITU)


Faculty of Engineering
Example

1 N

Slide 3- 50

Information Technology University (ITU)


Faculty of Engineering
Example

1 1

Slide 3- 51

Information Technology University (ITU)


Faculty of Engineering
Example

1 N

Positio
n descriptio
PID Pname iid
n

Slide 3- 52

Information Technology University (ITU)


Faculty of Engineering
Example

1 1

Slide 3- 53

Information Technology University (ITU)


Faculty of Engineering
Example

1 1
1 1 1 N

1 N

Slide 3- 54

Information Technology University (ITU)


Faculty of Engineering

You might also like