er and eer modeling
TRANSCRIPT
Fundamentals of Database Systems
Nandana Pathirage BSc (Hons) in Computing (UK), MSc in SBIT (UK), MBCS
General Sir John Kotelawala Defence University
Lesson 2: Database Conceptual Design (ER and EER Models)
Learning Objectives:
1. Understand the role of high level conceptual data models
2. Know the concepts of the ER and EER models
3. Be able to build an ER or an EER model for a particular
application area
2.0 ER and EER ModelsAn ER model is an abstract way to describe a database. ER models are normally represented in an Entity Relationship Diagrams (ERD), which uses graphic representations to model the database components.
The Basic ER Model is based on the following components:
1.Entity
2.Attribute
3.Relationship
Top Down Bottom Up
ER Modeling Normalization
(Conceptual Model)
Logical Modeling Logical Modeling
Implementation Implementation
Entity- relationship modeling
What is Entity:
Is a person, place or thing about which data are to be collected and stored and which can be uniquely identified.
Entities can be thought of as nouns. Example: Student, Course, Artist, Song, Employee
Student CourseEnroll for
What is Attribute:
Properties that describes the entity.
Example: the entity STUDENT could have attributes such as Student_No, First Name, Last Name, Address
Student
S_No Name
Address
Cont.
Cont.
There are several types of attributes occur in the ER model:
1. Simple (Atomic) versus Composite:
Attributes that are not divisible are called simple or atomic attributes. Composite attributes can be divided into smaller subparts, which represent more basic attributes with independent meanings.
2. Single Valued versus Multi Valued:
Most attributes have a single value for a particular entity; such attributes are called Single- Valued.
In some cases an attribute can have a set of values for the same entity; such a attributes are called Multi-Valued.
3. Stored versus Derived:
In some cases, two (or more) attribute values are related –
For example, the Age and BirthDate 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 BirthDate. The Age attribute is hence called a Derived Attribute and is said to be derivable from the BirthDate attribute, which is called a Stored Attribute.
What is Relationship:
Describes an association between two or more entities.
For example STUDENT enroll for many courses and EMPLOYEE has many skills.
Student CourseEnroll for
Cont.
Cont.
A relationship can have one of three different cardinalities :
1. One-to-Many (1:M):
A painter paints many different paintings, but each one of them is painted by only that painter.
Painter PaintingPaints1 M
Cont.
2. Many-to-Many (M:N):
Student can enroll for many courses, and many students might learn each course.
Student CourseEnroll for
M N
3. One-to-One (1:1):
In a retail organization’s management structure, a single employee manages a single department and in turn single employee manages each department.
Manager DepartmentManages
1 1
A relationship can have optionality:
1. Partial Participation
2. Total Participation
Student CourseEnroll for
M N
Total participation Partial participation
Cont.
In addition to cardinality, a relationship has a degree:
That is the number of participating entity types in the relationship.
1. Unary relationship
Employee Managed by
M
1
Cont.
2. Binary relationship
A relationship with degree two is called a binary relationship.
Student CourseEnroll
forM N
3. Ternary relationship
A relationship with three degree is called a ternary relationship.
Salesman CustomerSold
by
Product
Attribute of Relationship
Relationship itself also can have attributes.
Qty
M NItem Purchase
Order
Pencil
Pen
Eraser
101
102
20
30
Weak entities and defining relationship:
Entity without proper primary key is a weak entity. In a weak entity instances are identified using its partial primary key + primary key of owner entity.
Hotel RoomContains1 N
ClassName
Place
Room No Type
Rate
Defining relationship
Enhanced Entity-Relationship Modeling (EER)
The EER model includes all the modeling concepts of the ER model. In addition, it includes the concepts of subclass and superclass, inheritance and the related concepts of specialization and generalization. Another concept included in the EER model is that of a category or union type.
Subclass and Superclass
An entity type is used to represent both a type of entity and the entity set or collection of entities of that type that exist in the database.
For example, the entity type EMPLOYEE describes the type (i,.e. the attributes and relationships) of each employee entity, and also refers to the current set of EMPLOYEE entities in the company database.
But in many cases an entity type has numerous sub groupings of its entities that are meaningful and need to be represented explicitly because of their significance to the database application.
Undergraduate
S_No
Name
d
Year of Study
Earned Degree
Student
TaughtPostgraduate
Research Postgraduate
U U UTutors Unit
Inheritance
For example,
EMPLOYEE entity can be grouped further into SECRETARY, ENGINEER, MANAGER, TECHNICIAN etc…
Based on the employees job
EMPLOYEE entity can be grouped further into SALARIED_EMPLOYEE, HOURLY_EMPLOYEE etc…
Based on the employee’s method of pay
Secretary
Name
E_No
d
Typing Speed T_Grade
Employee
Engineer Technician
Each employee instance Should not connected to one of these subtypes
Eng_Type
U
U U
Disjoint, partial
Address
Car
Make
Reg_No
d
Passenger Capacity
Cargo Capacity
Vehicle
Van Truck
Each Vehicle instance Should not connected to one of these subtypes
Load
U
U U
Disjoint, partial
Salaried Employee
Name
E_No
d
Salary
Employee
Hourly Employee
Each employee instance should connected to one of these subtypes
Pay_Scale
UU
Disjoint, total
Address
Further on Subclasses and Superclasses
Each of these subgroupings is a subset of EMPLOYEE entities
Each is called a subclass of EMPLOYEE EMPLOYEE is the superclass for each of these subclasses These are called superclass/subclass relationships:• EMPLOYEE/SECRETARY• EMPLOYEE/TECHNICIAN• EMPLOYEE/MANAGER• …
These are also called IS-A relationships
SECRETARY IS-A EMPLOYEE, TECHNICIAN IS-A EMPLOYEE, ….
Note: An entity that is member of a subclass represents the same real-world entity as some member of the superclass:
• The subclass member is the same entity in a distinct specific role
• An entity cannot exist in the database merely by being a member of a subclass; it must also be a member of the superclass
• A member of the superclass can be optionally included as a member of any number of its subclasses
Specialization is the process of defining a set of subclasses of a superclass
The set of subclasses is based upon some distinguishing characteristics of the entities in the superclass
• Example: {SECRETARY, ENGINEER, TECHNICIAN} is a specialization of EMPLOYEE based upon job type.
• May have several specializations of the same superclass Another specialization of EMPLOYEE based on method of
pay is {SALARIED_EMPLOYEE, HOURLY_EMPLOYEE}. Attributes of a subclass are called specific or local attributes.• For example, the attribute TypingSpeed of SECRETARY
Generalization Generalization is the reverse of the specialization
process Several classes with common features are generalized
into a superclass; original classes become its subclasses
Example: CAR, TRUCK generalized into VEHICLE; • both CAR, TRUCK become subclasses of the superclass
VEHICLE.• We can view {CAR, TRUCK} as a specialization of
VEHICLE • Alternatively, we can view VEHICLE as a generalization
of CAR and TRUCK
Constraints on Specialization and Generalization
Two basic constraints can apply to a specialization/generalization:
• Disjointness Constraint: • Completeness Constraint:
Disjointness Constraint: Specifies that the subclasses of the specialization must be
disjoint:
an entity can be a member of at most one of the subclasses of the specialization.
Specified by d in EER diagram If not disjoint, specialization is overlapping:
that is the same entity may be a member of more than one subclass of the specialization.
Specified by o in EER diagram
Completeness Constraint: Total specifies that every entity in the superclass must be a
member of some subclass in the specialization/generalization
Shown in EER diagrams by a double line
Partial allows an entity not to belong to any of the subclasses
Shown in EER diagrams by a single line
Hence, we have four types of specialization/generalization: Disjoint, total Disjoint, partial Overlapping, total Overlapping, partial
Note: Generalization usually is total because the superclass is derived from the subclasses.