You are on page 1of 71

CONTENT

▪ ER Model Basics
• Entity
• Entity Type
• Attribute
• Attribute Type
• Key and Key Attributes
• Relationship
• ER Diagram Example
▪ References
ER MODELING -TOP DOWN APPROACH

▪ A design method which works on Conceptual level based on


perception of real world.
▪ A graphical technique for understanding and organizing the data
independent of the actual database implementation.
ER MODEL BASICS

▪ Entities (objects): Any thing that may have an independent


existence and distinct from other entities based on their
attributes.
• e.g. Customers, Accounts, Trainee, Student etc.
▪ Attributes: Properties/characteristics that describe a entity.
• e.g.: Student Name, DOB, Address, etc.
▪ Relationships: Associations between entities.
• e.g. Account A-101 is held by customer Johnson etc.
ER MODELING - NOTATIONS
Entity And Entity Set

▪Entity:
• Real-world object distinguishable from other objects.
• E.g. customers, accounts, bank branch

▪Entity Set:
• A collection of similar entities. E.g., all employees.
Attributes

▪ Attribute describe the property of entity and relationship.

▪ The set of possible values for an attribute is called the


domain of the attribute.
• e.g.: The domain of attribute “marital status” is having four values: single,

married, divorced or widowed.

• e.g. :The domain of the attribute “month” is having twelve values ranging from

January to December.
Attributes Types
Types of Attributes Definition Example

Simple attribute Gender of the employee


Cannot be divided into simpler components

Address of the
Composite attribute Can be split into components
employee

Can take on only a single value


Single valued Age of the employee
for each entity instance

Multi-valued Can take up many values Skill set of the employee

Attribute that can be calculated based on other Years of service experience of


Derived Attribute attributes. the employee can be derived
from DOJ (date of joining)
ER MODELING - NOTATIONS

Composite attribute

Represented by an ellipse from which other ellipses emanate and represent the
component attributes. E.g Address
Key Attributes

▪ A group of one or more attributes that uniquely identify an entity in


the entity set.
▪ i.e. the attribute (or combination of attributes) that is unique for
every entity instance.
▪ e.g.: the account number of an account, the employee id of an
employee etc.
ER MODELING - NOTATIONS
ER MODELING - EXAMPLE
ER MODELING - EXAMPLE

Bank Information System


ER MODELING - EXAMPLE

On Line Book Shop


Entity Types
▪ Regular Entity: Entity that has its own key attribute (s).
• e.g.: Employee, student ,customer, policy holder etc.

▪ Weak entity: Entity that depends on other entity for its existence
and doesn’t have key attribute (s) of its own.
• e.g. : spouse of employee
ER MODELING - NOTATIONS

Attributes of a Relationship

These attributes best describe the relationship prescription rather than any
individual entity Doctor, Patient or Medicine.
Degree of a Relationship

▪ Degree: the number of entity types involved


• One Unary
• Two Binary
• Three Ternary

▪ e.g.:
1.employee manager-of employee is unary
2.employee works-for department is binary
3.Customer purchases items from a shopkeeper (a relationship in
which 3 entities are participating is called Ternary relationship)
• Here customer purchase item, shop keeper is a ternary
relationship
ER MODELING - NOTATIONS

Unary Relationship

• A unary relationship is represented as a diamond which connects one entity to itself as a loop.

• The relationship above means, some instances of employee manage other instances of
Employee.
ER MODELING - NOTATIONS

Binary Relationship

A relationship between two entity types


ER MODELING - NOTATIONS

Ternary Relationship

A relationship connecting three entity


types.
MAPPING OF CARDINALITY
Cardinality
▪ Relationships can have different connectivity
• one-to-one (1:1)
• one-to-many (1:N)
• many-to-one (M:1)
• many-to-many (M:N)

▪ e.g.:
• Employee head-of department (1:1)
• Lecturer offers course (1:N) assuming a course is taught by a single lecturer
• Student enrolls course (M:N)
▪ The minimum and maximum values of this connectivity is called the cardinality of the relationship.
▪ Cardinality defines the possible number of occurrences in one entity which is associated with the
number of occurrences in another. For example, ONE team has MANY players. When present in an
ERD, the entity Team and Player are inter-connected with a one-to-many relationship.
Relationship Participation

▪ Total Participation: Every entity instance must be connected through the


relationship to another instance of the other participating entity types
▪ Partial Participation : All instances need not participate

▪ e.g.: Employee Head-of Department


• Employee: partial
• Department: total

▪ All employees will not be head-of some department. So only few


instances of employee entity participate in the above relationship.
But each department will be headed by some employee.
▪ So department entity’s participation is total and employee entity’s
participation is partial in the above relationship.
ER MODELING - NOTATIONS

Relationship participation

•All instances of the entity type Employee don’t participate in the relationship, Head-of.
•Every employee doesn’t head a department. So, employee entity type is said to partially participate in the relationship.
•But, every department would be headed by some employee.
•So, all instances of the entity type Department participate in this relationship. So, we say that it is total participation from the
department side.
ER MODELING - NOTATIONS

An Entity can be defined as an object or concept


about which user wants to store information.

A weak Entity requires another Entity for it’s


existence. Example Order Item depends upon Order
Number for its existence. Without Order Number it is
impossible to identify Order Item uniquely.

Properties or characteristics of an Entity is called


Attributes of entity.

If an attribute is the unique or distinguishing


characteristic of the Entity it is called Key Attribute

If an attribute can have more than one value then it


is called multi-valued attribute.

For example, an employee Entity can have multiple


skill values.
Copyright © 2008, Infosys Technologies Ltd.
ER MODELING - NOTATIONS

If the value of an attribute can be derived from


another attribute it is called derived attribute.
For example, an employee's monthly salary is
based on the employee's basic salary and House
rent allowance.

Relationships in ER Diagram illustrate how two


entities of database share information.

We connect a weak entity through a strong entity


using a weak relationship notation.
CONTENT

▪ Introduction to Relational Data Model


▪ Key
▪ Types of Keys
▪ Relationship between keys
▪ References
Relational Data Model

▪ Data is viewed as existing in two dimensional tables known as


relations
▪ A relation (table) consists of unique attributes (columns) and
tuples (rows)
▪ Relational Database: Any database whose logical
organization is based on relational data model.
▪ RDBMS: A DBMS that manages the relational database.
▪ Relational database simplifies the database structure by making
use of tables.
▪ This model was first proposed by E. F. Codd.
Null Values

▪ Sometimes the value to be inserted into a particular cell may be unknown, or it may
have no value.
▪ This is represented by a NULL
▪ Null is not the same as zero, blank or an empty string
Key in a Relation

• A unique value for an entity. EmpNo EName EDeptNo


1001 Elsa D1
• An attribute or a set of attributes which can uniquely
1002 John D2
identify all the entities of the entity set (or each record
of a table). 1003 Maria Null
• Here, EmpNo is the key for this Relation. 1004 Maida D1
Types Of Keys

1. Super Key:
BookID Name Author
▪ a set of attributes which specifies that no two tuples (of a relation) is same.
OR 1001 X D1

‘K’ is the super key of a Schema ‘R’ if values for k are sufficient to identify 1002 Y D2
unique tuple of each possible relation r(R).
1003 X D3
▪ No two tuples can have same values for super key.
1004 M D1
▪ Super set of super key is also a super key.

▪ E.g.: Super key set-


{Name, Author},
{BookID},
{BookID, Name, Author}
Types Of Keys

2. Candidate Key:
BookID Name Author

▪ Minimal super key (super key without redundancy) is known as Candidate Key. 1001 X D1
▪ A Candidate key is not reducible as it has no redundancy.
▪ However, any subset of these set of attributes would not identify a row 1002 Y D2
uniquely
1003 X D3
▪ There can be more than one candidate keys in a relation.
▪ Overlapping candidate keys: Two candidate keys overlap if they involve any 1004 M D1
attribute in common.

▪ E.g.: Candidate Key:


{Name, Author}
{BookID}
▪ {BookID,Name, Author} is not a candidate key as BookID alone is able to
uniquely identify a tuple.
Key Attributes and Non Key Attributes

▪ Key Attributes:
• The attributes that participate in the Candidate key are Key attributes

▪ Non-Key Attributes:
• The attributes which do not participate in the Candidate key.
Types Of Keys
Primary key:
▪ During the creation of the table, the Database Designer chooses one of the Candidate
Key amongst the several available, to uniquely identify row in the given table.
▪ The candidate key that is chosen to perform the identification task is called the
primary key
▪ Composite primary key : A primary key which is a combination of more than one
attribute.
▪ Every tuple must have, by definition, a unique value for its primary key.
▪ While Selecting Primary Key:
• Give preference to numeric column(s)
• Give preference to single attribute
• Give preference to minimal composite key
Types Of Keys

Alternate Key:
▪ The candidate key that is chosen to perform the identification task is
called the primary key and the remaining candidate keys are known
as alternate keys.
▪ No of Alternate Keys = No of Candidate Keys - 1
EXAMPLE
Relationship Between Keys

Primary Key

Candidate Key

Super Key
Types Of Keys

Foreign key
▪ This key established relation between two tables (relation).
▪ A Foreign Key is a set of attribute (s) of a table, whose values are required to match values of some Candidate
Key in the same or another table
▪ Usually a foreign key is a “copy” of a primary key that has been exported from one relation into another to
represent the existence of a relationship between them.
▪ Foreign Key column must match the values of the corresponding Candidate Key column. This is known as
Referential constraint.
▪ A table which has a Foreign Key referring to its own Candidate Key is known as Self-Referencing table
▪ Foreign key is used to keep database small and to reduce redundancy.
▪ To enter the data in child table corresponding data must be present in master table
or NULL is the default entry in child table in the referenced column ( FK column)
▪ Foreign key values do not (usually) have to be unique.
▪ Foreign keys can also be null .

DEPT EMP
(Parent /Master/Referenced Table) (Child /Referencing Table)

DeptNo DName EmpNo EName EDeptN


o
1001 Elsa D1
D1 IVS
1002 John D2
D2 ENR
1003 Maria Null

1004 Maida D1
DEPT TABLE HAS DEPTNO AS PRIMARY
KEY
EMP TABLE HAS ALSO DEPTNO BUT HERE
IT IS FOREIGN KEY
TOPIC:
EXTENDED E-R MODEL FEATURE-
GENERALIZATION AND
SPECIALIZATION
INTRODUCTION:

• E-R diagram represents that basic concepts of the DB schema.


• Inheritance among various entity types cannot be expressed using basic E-R model.
• Enhancing diagram are known as extended E-R or EER diagrams Certain features
cannot be expressed using basic ER Model.
• Such features are expressed using Extended ER Model.
• Extended features of an ER Model are:
1. Specialization
2. Generalization
3. Aggregation
SPECIALIZATION

• Top-down design process


• We designate subgroupings within an entity set that are distinctive from other entities
in the set.
• These subgroupings become lower-level entity sets that have attributes or participate
in relationships that do not apply to the higher-level entity set.
• The entity type containing common attributes known as superclass.
• The entity type which is a subset of the superclass known as subclass.
• Process of refining superclass(higher level entity type) into subclasses (low level
entity type) by adding some additional features to each of them is a top down design
approach.
GENERALIZATION

• A bottom-up design process


• It combine a number of entity sets that share the same features
into a higher-level entity set.
• Specialization and generalization are simple inversions of each
other; they are represented in an E-R diagram in the same way.
• Depicted by a triangle component labeled ISA
ISA
EXAMPLE

• Entity set -> person

• Attributes->{person_id,name,street,city}

person_id name street city

person
A person can be further classified into following entity sets:
• customer
Attributes ->{customer_id,customer_name,customer_street,
customer_city,credit_rating}

customer_i Customer customer customer Credit_r


d _name _street _city ating

customer
• employee
Attributes ->{employee_id, employee_name,employee_street,
employee_city,salary}

employee employee employee employee


_id salary
_name _street _city

employee
• The process of designing subgroupings within an entity set is called specialization.

person

ISA

employee customer
We can apply specialization repeatedly to refine a design scheme.
• For example : employee can be further classified as follows:
• officer
Attributes ->{officer_id, officer_name, officer_street,
officer_city,officer_salary,office_number}
• teller
Attributes ->{teller_id, teller_name, teller_street, teller_city,
teller_salary,station_number,hours_worked}
• secretary
Attributes ->{secretary_id, secretary_name, secretary_street, secretary_city,
secretary_salary,hours_worked}
• It can be represented as follows:

employee

ISA

officer teller secretary


EXTENDED ER DIAGRAM SHOWING
GENERALIZATION AND SPECIALIZATION
AGGREGATION

• Represent the relationships between two or more entities.


• E-R diagram cannot represent the relationship among
relationship.
• Aggregation represents relationship among relationship.
LET US CONSIDER AN EXAMPLE:
E-R DIAGRAM WITH AGGREGATION
• Without introducing redundancy, the following diagram
represents:
• An employee works on a particular job at a particular branch
• An employee, branch, job combination may have an associated
manager
AGGREGATION (CONT.)
▪ Relationship sets works_on and manages represent overlapping information
▪ Every manages relationship corresponds to a works_on relationship
▪ However, some works_on relationships may not correspond to any manages
relationships
▪ So we can’t discard the works_on relationship
▪ So we eliminate this redundancy via aggregation
▪ Treat relationship as an abstract entity
▪ Allows relationships between relationships
▪ Abstraction of relationship into new entity
THANK
YOU

You might also like