Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

Database Chapter_4 Lecture Note

The document discusses the Enhanced Entity-Relationship (EER) model, which extends the basic ER model by incorporating additional concepts such as subclasses, specialization, generalization, and attribute inheritance. It explains the relationships between superclasses and subclasses, detailing how entities can inherit attributes and how specialization and generalization processes work. Additionally, it covers constraints on specialization and generalization, as well as SQL join types for retrieving data from multiple tables.

Uploaded by

Tesfalegn Yakob
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Database Chapter_4 Lecture Note

The document discusses the Enhanced Entity-Relationship (EER) model, which extends the basic ER model by incorporating additional concepts such as subclasses, specialization, generalization, and attribute inheritance. It explains the relationships between superclasses and subclasses, detailing how entities can inherit attributes and how specialization and generalization processes work. Additionally, it covers constraints on specialization and generalization, as well as SQL join types for retrieving data from multiple tables.

Uploaded by

Tesfalegn Yakob
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

CHAPTER FOUR

Enhanced Entity –Relationship


And
Object modeling
• EER stands for Enhanced ER or Extended ER
• EER Model Concepts
– Includes all modeling concepts of basic ER
– Additional concepts:
• subclasses/super classes
• specialization/generalization
• categories (UNION types)
• attribute and relationship inheritance
• The resulting model is called the Enhanced-ER or
Extended ER (E2R or EER) model
• It is used to model applications more completely and
accurately if needed
• It includes some object-oriented concepts, such as
inheritance .
Enhanced E-R (EER) Models
• Object-oriented extensions to E-R model
• EER is important when we have a relationship
between two entities and the participation is
partial between entity occurrences. In such
cases EER is used to reduce the complexity in
participation and relationship complexity.
• ER diagrams consider entity types to be
primitive objects
• EER diagrams allow refinements within the
structures of entity types
Subclasses and Subtype
• When one generalized Superclass has various subgroups
with distinguishing features and these subgroups are
represented by specialized form, the groups are called
subclasses.
• An entity type may have additional meaningful sub
groupings of its entities.
Example: EMPLOYEE may be further grouped into SECRETARY,
ENGINEER, MANAGER, TECHNICIAN, SALARIED_EMPLOYEE,
HOURLY_EMPLOYEE,…
– Each of these groupings is a subset of EMPLOYEE entities
– Each is called a subclass of EMPLOYEE
– EMPLOYEE is the super class for each of these subclasses
• These are called super class/subclass relationships.
Example: EMPLOYEE/SECRETARY, EMPLOYEE/TECHNICIAN
Con’t
 Subclasses can be either mutually exclusive (disjoint) or
overlapping (inclusive).
 A single subclass may inherit attributes from two distinct super
classes.
 A mutually exclusive category/subclass is when an entity
instance can be in only one of the subclasses. E.g.: An
EMPLOYEE can either be SALARIED or PART-TIMER but
not both.
 An overlapping category/subclass is when an entity instance
may be in two or more subclasses.
E.g.: A PERSON who works for a university can be both
EMPLOYEE and a STUDENT at the same time.
Superclass /Super type
• An entity type whose tuples have attributes that distinguish its
members from tuples of the generalized or Superclass entities.
• An entity type whose tuples share common attributes.
Attributes that are shared by all entity occurrences (including
the identifier) are associated with the super type.
• Is the generalized entity.

Relationship Between Superclass and


Subclass
 The relationship between a superclass and any of its subclasses
is called a superclass/subclass or class/subclass relationship
 An instance can not only be a member of a subclass. i.e. Every
instance of a subclass is also an instance in the Superclass.
Con’t
 A member of a subclass is represented as a distinct database object, a
distinct record that is related via the key attribute to its super-class entity.
 An entity cannot exist in the database merely by being a member of a
subclass; it must also be a member of the superclass.
 An entity occurrence of a sub class not necessarily should belong to any
of the subclasses unless there is full participation in the specialization.
 The relationship between a subclass and a Superclass is an “IS A/AN” or
“IS PART OF” type.
 Subclass IS PART OF Superclass
 Manager IS AN Employee
 All subclasses or specialized entity sets should be connected with the
superclass using a line to a circle where there is a subset symbol
indicating the direction of subclass/superclass relationship.
Con’t

 We can also have subclasses of a subclass forming a hierarchy of


specialization.
 Superclass attributes are shared by all subclasses of that superclass
 Subclass attributes are unique for the subclass.
Attribute Inheritance in Superclass /
Subclass Relationships
• An entity that is a member of a subclass inherits all the
attributes of the entity as a member of the superclass.
• The entity also inherits all the relationships in which the
superclass participates.
• An entity may have more than one subclass categories.
• All entities/subclasses of a generalized entity or
superclass share a common unique identifier attribute
(primary key). i.e. The primary key of the superclass and
subclasses are always identical.
example
• Consider the EMPLOYEE supertype entity shown
above. This entity can have several different subtype
entities (for example: HOURLY and SALARIED),
each with distinct properties not shared by other
subtypes. But whether the employee is HOURLY or
SALARIED, same attributes (EmployeeId, Name,
and DateHired) are shared.
• The Supertype EMPLOYEE stores all properties that
subclasses have in common. And HOURLY
employees have the unique attribute Wage (hourly
wage rate), while SALARIED employees have two
unique attributes, Stock Option and Salary.
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.
• Is the result of subset of a higher level entity set to form a
lower level entity set.
• The specialized entities will have additional set of attributes
(distinguishing characteristics) that distinguish them from the
generalized entity.
• Is considered as Top-Down definition of entities.
• Identify the distinguishing features of some entity
occurrences, and specialize them into different subclasses.
Con’t
Reasons for Specialization
 Attributes only partially applying to super classes
 Relationship types only partially applicable to the
superclass .
• Example: {SECRETARY, ENGINEER, TECHNICIAN} is a specialization of
EMPLOYEE based upon job type.
– May have several specializations of the same superclass
• Example: Another specialization of EMPLOYEE based in method of
pay is {SALARIED_EMPLOYEE, HOURLY_EMPLOYEE}.
– Superclass/subclass relationships and specialization can be
diagrammatically represented in EER diagrams
– Attributes of a subclass are called specific attributes. For
example, Typing Speed of SECRETARY
– The subclass can participate in specific relationship types. For
example, BELONGS_TO of HOURLY_EMPLOYEE
Example of a Specialization
Generalization
• Generalization is the process of defining a more
general entity type from a set of more specialized
entity types.
• It occurs when two or more entities represent
categories of the same real-world object.
• A generalization hierarchy is a form of abstraction that
specifies two or more entities that share common
attributes can be generalized into a higher level entity
type.
• Is considered as bottom-up definition of entities.
• Generalization hierarchy depicts relationship between
higher level superclass and lower level subclass.
Con’t
• The reverse of the specialization process
• Several classes with common features are generalized
into a superclass; original classes become its
subclasses
• Example1: 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
Example: Account is a generalized form Saving and Current
Accounts
Generalization and Specialization
• Diagrammatic notation sometimes used to distinguish between
generalization and specialization
– Arrow pointing to the generalized superclass represents a
generalization
– Arrows pointing to the specialized subclasses represent a
specialization
– We do not use this notation because it is often subjective as
to which process is more appropriate for a particular
situation
– We advocate not drawing any arrows in these situations
• Data Modeling with Specialization and Generalization
– A superclass or subclass represents a set of entities
– Shown in rectangles in EER diagrams (as are entity types)
– Sometimes, all entity sets are simply called classes,
whether they are entity types, superclasses, or subclasses
Constraints on specialization and generalization
• If we can determine exactly those entities that will become
members of each subclass by a condition, the subclasses are
called predicate-defined (or condition-defined) subclasses
– Condition is a constraint that determines subclass members
– Display a predicate-defined subclass by writing the
predicate condition next to the line attaching the subclass
to its superclass
• If all subclasses in a specialization have membership condition
on same attribute of the superclass, specialization is called an
attribute defined-specialization
– Attribute is called the defining attribute of the
specialization
– Example: JobType is the defining attribute of the
specialization {SECRETARY, TECHNICIAN,
ENGINEER} of EMPLOYEE
• If no condition determines membership, the subclass
is called user-defined
– Membership in a subclass is determined by the
database users by applying an operation to add an
entity to the subclass
– Membership in the subclass is specified
individually for each entity in the superclass by the
user
Two other conditions apply to a specialization/generalization:
Completeness Constraint.
• The Completeness Constraint addresses the issue of whether
or not an occurrence of a Superclass must also have a
corresponding Subclass occurrence.
• The completeness constraint requires that all instances of the
subtype be represented in the supertype.
• The Total Specialization Rule specifies that an entity
occurrence should at least be a member of one of the
subclasses.
E.g.: If we have EXTENTION and REGULAR as subclasses of
a superclass STUDENT, then it is mandatory that each student to
be either EXTENTION or REGULAR student. Thus the
participation of instances of STUDENT in EXTENTION and
REGULAR subclasses will be total.
The Partial Specialization Rule specifies that it is not necessary
for all entity occurrences in the superclass to be a member of one
of the subclasses.
• Here we have an optional participation on the specialization.
E.g.: If we have MANAGER and SECRETARY as subclasses of a
superclass EMPLOYEE, then it is not the case that all employees
are either manager or secretary. Thus the participation of instances
of employee in MANAGER and SECRETARY subclasses will be
partial.
Disjointness Constraints:
• Specifies the rule whether one entity occurrence
can be a member of more than one subclasses. i.e.
it is a type of business rule that deals with the
situation where an entity occurrence of a
Superclass may also have more than one Subclass
occurrence.
• The Disjoint Rule restricts one entity occurrence
of a superclass to be a member of only one of the
subclasses.
Example: an EMPLOYEE can either be SALARIED or
PART-TIMER, but not both at the same time.
• The Overlap Rule allows one entity occurrence to be a
member of more than one subclass.
Example: EMPLOYEE working at the university can be both
a STUDENT and an EMPLOYEE at the same time.
• This is diagrammed by placing either the letter "d" for
disjoint or "o" for overlapping inside the circle on the
Generalization Hierarchy portion of the E-R diagram.
• The two types of constraints on generalization and specialization
(Disjointness and Completeness constraints) are not dependent
on one another.
• That is, being disjoint will not favor whether the tuples in the
superclass should have Total or Partial participation for that specific
specialization.
• From the two types of constraints we can have four possible
constraints
 Disjoint AND Total
 Disjoint AND Partial
 Overlapping AND Total
 Overlapping AND Partial
SQL Joins
 The SQL Joins clause are used to fetch/retrieve data from two or more tables
based on the join condition which is specified in the WHERE condition.
 It is also used to relate information in different tables.
 A Join condition is a part of the SQL query that retrieves rows from two or
more tables.
 The SQL Joins clause is used to combine records from two or more tables in a
database.
 Basically data tables are related to each other with keys. We can used these
keys relationship in SQL joins.
SQL Join Types:
There are different types of joins available in SQL:
INNER JOIN:
 All the rows returned by the SQL query satisfy the SQL join condition specified.
 Returns rows when there is a match in both tables.
 The most frequently used and important of the joins is the INNER JOIN.
Con’t
Syntax:
SELECT table1.column1, table2.column2...
FROM table1
INNER JOIN table2
ON table1.common_filed = table2.common_field
LEFT JOIN
 The SQL LEFT JOIN returns all rows from the left table, even if there are
no matches in the
 right table. This means that if the ON clause matches 0 (zero) records in
right table, the join will still return a row in the result, but with NULL in
each column from right table.
 This means that a left join returns all the values from the left table, plus
matched values from the right table or NULL in case of no matching join
predicate.
Con’t

RIGHT JOIN
 The SQL RIGHT JOIN returns all rows from the right table, even if there are no matches
in the left table. This means that if the ON clause matches 0 (zero) records in left table,
the join will still return a row in the result, but with NULL in each column from left table.
 This means that a right join returns all the values from the right table, plus matched
values from the left table or NULL in case of no matching join predicate.

FULL JOIN:
 The SQL FULL JOIN combines the results of both left and right outer joins.
 The joined table will contain all records from both tables, and fill in NULLs for missing
matches on either side.
 returns rows when there is a match in one of the tables.
SELF JOIN:
 is used to join a table to itself as if the table were two tables, temporarily renaming at
least one table in the SQL statement.

You might also like