Unit 2 - Relational Data Model and ERModel (1)
Unit 2 - Relational Data Model and ERModel (1)
Binary Operations
◦ Operates on Minimum two or more relation.
◦ Binary Operators are : Cartesian Product, Union, Set Difference.
Selection Operation
Selection Operation
Projection Operation
The Project Operation allow projecting the selected attributes from relations.
Projection Operation
Projection with Selection Operation
Binary Operations
Takes as input two relation instances
Four standard operations
◦ Union
◦ Set-difference
◦ Cross-product
The result contains one tuple <r,s> for each pair with r ⋳ R and s ⋳ S
Basically, it is the Cartesian product.
Fields of the same name are unnamed.
Cross-Product
Renaming
Name conflict can arise in some situations
It is convenient to be able to give names to the fields of a relation instance
defined by a relational algebra expression.
Rename Operation
Entity Relationship Model
Overview of Database Design Process
Two main activities:
◦ Database design
◦ Applications design
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
Overview of Database Design Process
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.
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.
ER Model
Peter Pin-Shan Chen is a Taiwanese American computer scientist. He is a Distinguished Career
Scientist and faculty member at Carnegie Mellon University, who is known for the development
of the entity-relationship model in 1976.
ER Model
The entity-relationship model is Graphical representation of entities and their relationships in a
database structure.
ER models are normally represented in an entity relationship diagram(ERD), which uses
graphical representations to model database components.
Entity Relationship Diagram (ERD) A detailed, logical representation ofthe entities, associations
and dataelements for an organization or business
ER Model Components
ER Model Components
◦ Entities are specific objects or things in the real-world that are represented in the
database.
◦ The name of the entity, a noun, is written in the center of the rectangle.
◦ For example the EMPLOYEE John Smith, the Research DEPARTMENT, the ProductX PROJECT
Previous slide shows three CAR entity instances in the entity set for CAR
Same name (CAR) used to refer to both the entity type and the entity set
Entity set is the current state of the entities of that type that are stored in the database
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
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.
Degree of relationship
Degree: The number of entity types that participate in a relationship
For eg. Both MANAGES and WORKS_ON are binary relationships.
Types –
Unary: between two instances of one entity type
Binary: between the instances of two entity types
Ternary: among the instances of three entity types
Cardinality
It defines relationships between entities by placing the relationship in the context of numbers. In
an email system, for example, one account can have multiple contacts.
Relationship instances of the WORKS_FOR N:1 relationship between
EMPLOYEE and DEPARTMENT
Relationship instances of the M:N WORKS_ON relationship
between EMPLOYEE and PROJECT
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)
ER DIAGRAM – Relationship Types are:
WORKS_FOR, MANAGES, WORKS_ON, CONTROLS, SUPERVISION, DEPENDENTS_OF
Discussion on Relationship Types
In the refined design, some attributes from the initial entity types are refined
into relationships:
◦ Manager of DEPARTMENT -> MANAGES
◦ Works_on of EMPLOYEE -> WORKS_ON
◦ Department of EMPLOYEE -> WORKS_FOR
◦ etc
In general, more than one relationship type can exist between the same
participating entity types
◦ MANAGES and WORKS_FOR are distinct relationship types between EMPLOYEE and
DEPARTMENT
◦ Different meanings and different relationship instances.
Weak Entity Types
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
Example:
◦ A DEPENDENT entity is identified by the dependent’s first name, and the specific EMPLOYEE
with whom the dependent is related
◦ Name of DEPENDENT is the partial key
◦ DEPENDENT is a weak entity type
◦ EMPLOYEE is its identifying entity type via the identifying relationship type DEPENDENT_OF
Constraints on Relationships
Constraints on Relationship Types
◦ (Also known as ratio constraints)
◦ Cardinality Ratio (specifies maximum participation)
◦ One-to-one (1:1)
◦ One-to-many (1:N) or Many-to-one (N:1)
◦ Many-to-many (M:N)
◦ Existence Dependency Constraint (specifies minimum participation) (also called
participation constraint)
◦ zero (optional participation, not existence-dependent)
◦ one or more (mandatory participation, existence-dependent)
Notation for Constraints on Relationships
Cardinality ratio (of a binary relationship): 1:1, 1:N, N:1, or M:N
◦ Shown by placing appropriate numbers on the relationship edges.
Participation constraint (on each participating entity type): total (called existence dependency)
or partial.
◦ Total shown by double line, partial by single line.
Read the min,max numbers next to the entity type and looking
away from the entity type
COMPANY ER Schema Diagram using (min, max) notation
Alternative diagrammatic notation
Chen’s Notation
One to represent one
M to represent Many
Crows foot notation
Extended E-R features
EER is a high-level data model that incorporates the extensions to the original ER model.
It is a diagrammatic technique for displaying the following concepts
Sub Class and Super Class
Specialization and Generalization
Aggregation
Features of EER Model
EER creates a design more accurate to database schemas.
It reflects the data properties and constraints more precisely.
It includes all modeling concepts of the ER model.
Diagrammatic technique helps for displaying the EER schema.
It includes the concept of specialization and generalization.
Generalization
Generalization is the process of generalizing the entities which contain the properties of all the generalized
entities.
It is a bottom approach, in which two lower level entities combine to form a higher level entity.
Generalization is the reverse process of Specialization.
It defines a general entity type from a set of specialized entity type.
It minimizes the difference between the entities by identifying the common features.
Specialization
Specialization is a process that defines a group entities which is divided into sub groups based on
their characteristic.
It is a top down approach, in which one higher entity can be broken down into two lower level entity.
It maximizes the difference between the members of an entity by identifying the unique
characteristic or attributes of each member.
It defines one or more sub class for the super class and also forms the superclass/subclass
relationship.
Aggregation
Aggregation is a process that represent a relationship between a whole object and its
component parts.
It abstracts a relationship between objects and viewing the relationship as an object.
It is a process when two entity is treated as a single entity.
Reduction to E-R database schema
ER diagram is converted into the tables in relational model.
This is because relational models can be easily
implemented by RDBMS like MySQL , Oracle etc.