FALLSEM2023-24 BCSE302L TH VL2023240100688 2023-05-03 Reference-Material-I

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 40

Data Modeling using Entity

Relationship Model
Main Phases of Database Design
Phases of database design
Example Database Design
Example COMPANY Database (Partial Requirements)
Requirements of the Company
 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.
 Each department controls a number of PROJECTs.
 Each project has a name, number and is located at a
single location.
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
 Attributes are properties used to describe an entity. For
example an EMPLOYEE entity may have a 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, …
Types of Attributes (1)
Simple Attribute Vs Composite Attribute:
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).
Types of Attributes (2)
Single valued Vs Multi-valued:
Single Valued:
Attributes having single value for a particular entity-
Ex: RegNo
Multi valued:
An entity may have multiple values for that attribute.
For example,
PreviousDegrees of a STUDENT.
Denoted as {PreviousDegrees}.
Types of Attributes (4)
Stored Vs Derived Attributes
Consider Age and Birthdate.
Age is derived from the current date and the
value of the person’s Birthdate.

Age is derived attribute


Birthdate is stored attribute.
Null Values
◦ Not applicable- Person with no college degree
would have null
◦ Unknown-If we do not know the home phone
number of some XYZ.
Complex Attributes
 In general, composite and multi-valued attributes may
be nested arbitrarily to any number of levels although
this is rare.
Example 1
PreviousDegrees of a STUDENT is a composite multi-
valued attribute denoted by
{PreviousDegrees (College, Year, Degree, Field)}.
Example 2
{AddressPhone({phone(Areacode,Phone number)},
Address(Streetaddress(Number,street,Apartmentnumber),c
ity,state,zip))}
Entity Types,Entity Sets, Keys and value
Sets
Entity Type and Entity set

Entity Type
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.
Entity Set
 ENTITY SET corresponding to the ENTITY TYPE CAR
CAR
Registration(RegistrationNumber, State), VehicleID, Make, Model, Year,
(Color)

car1
((ABC 123, TEXAS), TK629, Ford Mustang, convertible, 1999, (red,
black))
car2
((ABC 123, NEW YORK), WP9872, Nissan 300ZX, 2-door, 2002, (blue))
car3
((VSY 720, TEXAS), TD729, Buick LeSabre, 4-door, 2003, (white, blue))
...
Key Attributes
Key Attribute:
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.

A key attribute may be composite.


For example,
 VehicleTagNumber is a key of the CAR entity type with components
(Number, State).
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.
Value Sets( Domains) of Attributes
Specifies the set of values that may be
assigned to the attribute for each
individual entity.
Ex: range of employee is 16 to 70
Relationships, Relationship Types,
Roles and Structural Constraints
Relationship
A relationship relates two or more distinct
entities with a specific meaning.
Example1:
EMPLOYEE John Smith works on the
ProductX PROJECT
Example 2:
EMPLOYEE Franklin Wong manages the
Research DEPARTMENT.
Relationship Types
A relationship type R among n entity types E1,E2,…
En defines a set of associations- or a relationship set
among entities from these types.
 Relationships of the same type are grouped or typed
into a relationship type.
Example,
 the WORKS_ON relationship type in
whichEMPLOYEEs and PROJECTs participate,
or
 the MANAGES relationship type in which
EMPLOYEEs and DEPARTMENTs participate.
Thedegree of a relationship type is the
number of participating entity types.
WORKS_FOR Is a binary relationships.
Example relationship instances of the
WORKS_FOR relationship between
EMPLOYEE and DEPARTMENT
Example relationship instances of the
WORKS_ON relationship between
EMPLOYEE and PROJECT
Recursive Relationships
More than one relationship type can exist with
the same participating entity types.
For example, SUPERVISION relationships
between
EMPLOYEE (in role of supervisor or boss) and
(another)
EMPLOYEE (in role of subordinate or worker).
In following figure, first role participation
labeled with 1 and second role participation
labeled with 2.
A RECURSIVE RELATIONSHIP
SUPERVISION

In ER diagram, need to display role names to distinguish


participations.
Role Names
Role Name signifies the role that a
participating entity from the entity type
playa in each relationship instance
Example: In the Works_For relationship
Employee plays the role of employee or
worker and department plays the role of
department or employer
Attributes of Relationship types
A relationship type can have attributes;
for
example,
HoursPerWeek of WORKS_ON;
Its value for each relationship instance
describes the number of hours per week
that an EMPLOYEE works on a
PROJECT.
Constraints on Relationship Types
Constraints limit the possible combination
of entities that may participate in the
corresponding relationship set.
Types of relationship constraints
◦ Cardinality ratio (maximum Cardinality)
◦ Participation(minimum cardinality)
Both together are called Structural
Constraints
Cardinality ratio for Binary relationships
 Maximum Cardinality – ( Also known as
ratio constraints )
◦ One-to-one (1:1)
◦ One-to-many (1:N) or Many-to-one (N:1)
◦ Many-to-many
Example-Maximum cardinality
In the works_for relationship
Employee :Department is of cardinality
N:1 means
Each department can be related to
numerous employees, but an employee
can be related to (work for) only one
department
Many-to-one (N:1) RELATIONSHIP
Many-to-many (M:N)
RELATIONSHIP
Participation Constraints
Specifies whether the existence of an
entity depends on its being related to
another entity via the relationship type.
Minimum Cardinality (also called
existence dependency constraints)
◦ one or more (mandatory, existence-
dependent)-total participation
◦ zero (optional participation, not existence-
dependent) –partial participation
Example
Total particiaption:
If a company policy states that every
employee must work for a
department,then an employee entity can
exist only if it participates in a works_for
relationship instance.
Participation of employee in works_for is
total particiaption
Example
Partial participation
Participation of employee in manages
relationship type is partial, meaning that
some or part of the set of employee
entities are related to department.
Relationships of Higher Degree
Relationship types of degree 2 are called
binary
Relationship types of degree 3 are called
ternary and of degree n are called n-ary
In general, an n-ary relationship is not
equivalent to n binary relationships
Example Database Design
Requirements of the Company
1. 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.
2. A department controls a number of PROJECTs.
Each project has a name, number and is located at a single
location.
Example Database Design
3.We store each employee’s name, social
security number, address, salary, sex and
birth date. An employee is assigned to one
department but may work on several
projects, which are not controlled by the
same department. We keep track of the
number of hours per week that an employee
works on each project. We also keep track
of the direct supervisor of each employee.
Example Database Design
4. We want to keep track of the dependents
of each employee for insurance policies.
We keep each dependent’s first name, sex,
birthdate and relationship to the
employee.
ER Diagram
Alternative (min, max) notation for relationship structural
constraints:

Specified on each participation of an entity type E in a relationship type R


Specifies that each entity e in E participates in at least min and at most
max relationship instances in R
Default(no constraint): min=0, max=n
Must have min≤max, min≥0, max ≥1
Derived from the knowledge of mini-world constraints
Examples:
A department has exactly one manager and an employee can manage at
most one department.
◦ Specify (0,1) for participation of EMPLOYEE in MANAGES
◦ Specify (1,1) for participation of DEPARTMENT in MANAGES
An employee can work for exactly one department but a department can
have any number of employees.
◦ Specify (1,1) for participation of EMPLOYEE in WORKS_FOR
◦ Specify (0,n) for participation of DEPARTMENT in WORKS_FOR
The (min,max) notation relationship
constraints
Company ER Schema using (min,max)
Notation
Importance of ER modeling 
Steps to implement a RDBMS
Problem Statement
->ER diagram
->Database tables
->Table Normalization
Given a problem statement, the first step is to identify the entities,
attributes and relationships.
We represent them using an ER diagram.
Using this ER diagram, table structures are created, along with
required constraints.
Finally, these tables are normalized in order to remove redundancy
and maintain data integrity.
Thus, to have data stored efficiently, the ER diagram must be drawn
as much detailed and accurate as possible.

You might also like