DBS Lecture#16 18
DBS Lecture#16 18
Super/Sub Types
Identifying Super/Sub Types (Generalization,
Specialization)
When to use Super/Sub Type
Completeness Constraint:
Total Specialization Rule
Partial Specialization Rule
Disjoint-ness constraints
Subtype Discriminator
Subtype Hierarchies
Transformation (Step 1 and Step 2)
TRANSFORMATION
EER INTO
RELATIONS
Transformation EER\Relations
The process of converting EER diagram
into Relation consist of different steps
In ER we have:
Entities(Regular,Weak,Associative),
Relationship(Degree,Cardinality)
Attributes(Single value,Multi-
values,Composite,Derived etc.)
Transformation
Step 1: Map Strong entities
Step 2: Map Weak Entities
Step 3: Map Binary Relationship
Step 4: Map Associative Entities
STEP 5: Map Unary Relationship
Step 6: Map Ternary Relations
Step 7: Map Super/Sub
STEP 1: Map Regular Entities
EMPLOYEE
Employee_ID
Employee_Name
Address
EMPLOYEE
EMPLOYEE
Employee_ID
Employee_Name
Address(Stree_Address, City, State)
EMPLOYEE
EMPLOYEE_SKILL
Employee_ID Skill
EMPLOYEE
Emp_ID Name Dept_Name Skill
150 C#
Step 2: Map Weak Entities
Weak entity is an entity type whose
existence depends on some other
entity type(Strong)
1. Define a new table for each weak
entity
2. The primary key of strong entity
relation serve to make foreign key in
the weak entity relation
Step 2: Map Weak Entities
Surrogate primary key
A serial number or other system
assigned primary key for a relation
Step 3: Map Binary Relationship
A relationship between two entities
known as binary relationship
The cardinality of Binary Relationship
can be of following types:
1:M
M:N
1:1
Step 3: Map Binary Relationship
One to Many Relationship(1:M)
1. Create relations(tables) for each entity
type participating in relationship
2. Include primary key attribute of one
side entity type in the table of many
side entity type as a foreign key
CUSTOMER ORDER
Customer_ID Submit Order_ID
Customer_Name Order_Date
Customer_Address
CUSTOMER
Customer_ID Customer_Name Customer_Address
ORDER
EMPLOYEE PROJECT
Employee ID Project ID
Employee Name Is_assigned Description
EMPLOYEE
Employee_ID Employee_Name
ASSIGNMENT
Employee_ID Project_ID Date_Assigned
PROJECT
Project_ID Project_Description
Step 3: Map Binary Relationship
One-to-One Relationship(1:1)
1. Two relations(tables) are created
one for each participating entity
2. Primary key of one of relation is
included as foreign key in the other
relation
Employee_ID Employee_Name Department_ID Department_Nam
EMPLOYE DEPARTMENT
Manages
EMPLOYEE
Employee_ID Employee_Name
Department
Department_ID Department_Name Employee_Manager
Step 4: Map Associative Entities
M:N relations may be converted into
Associative Entities
The process of Associative Entities is
same as the Many-to-Many binary
relationship
There may be two situations(identifier
defined or not defined)
Identifier Not Defined
Identifier Defined
STEP 5: Map Unary Relationship
Unary One-to-Many
The Unary entity type is mapped using
the procedure of Step 1
A recursive foreign key also included
in the relation
Recursive foreign key reference the
primary key value of same relation
Unary One-to-Many
Empl
oyee_
ID
Employee_Name
EMPLOYEE
Employee_ID Employee_Name Birth_Place Supervisor_ID
STEP 5: Map Unary Relationship
Unary Many-to-Many
Two relations are created one for the
entity type and other for relationship
A recursive foreign key also included
in the relation
Recursive foreign key reference the
primary key value of same relation
Item_
No
Quantity
ITEM Name
Contains
Unit_Cost
• ITEM(Item_No,Name,Unit_Cost)
• COMPONENT(Item_No, Component_No,
Quantity)
Unary Many-to-Many
COURSE
Course ID
Course Title
Is_
Prerequisite_
For
Many-to-Many Relationship
Is_
COURSE Prerequisite_
Course ID For
Course Title
Step 6: Map Ternary Relations
Ternary relationship is a relationship type in
which three participating entities are
involved
Good ER design is to convert this type of
relationship into three binary relationships
by making associative entity
We can transform ternary relation into tables
without this simplification
Step 6: Map Ternary Relations
1. Make a table for each participating
entity
2. Make one table for the relationship
3. The primary keys of all
participating tables work as foreign
key in relationship table
PART
Shipping_mode Unit_cost
• VENDER(….)
• PART(…….)
• WAREHOUSE(…….)
• SUPPLY_SCHEDULE(Part_No,Vendor_ID,War
ehouse_ID,Shipping_Mode,Unit_cost)
Step 7: Map Super/Sub
Relational data model did not support
Super/Sub Model. Following guidelines can
be uses:
1. Create separate relation for Super type and
each Sub
2. Assign common attributes to Super
Relation
3. Assign Primary key of Super to Sub
tables
Step 7: Map Super/Sub
Many strategies can be used to convert Super\Sub
relation, Most commonly used guidelines are as
following:
1. Create a separate relation for the supertype and for
each of its subtypes.
2. Assign to the relation created for the supertype the
attributes that are common
3. Assign to the relation for each subtype the primary
key of the supertype and unique attributes of
subtype.
4. Assign one (or more) attributes of the supertype to
function as the subtype discriminator
Step 7: Map Super/Sub
Step 7: Map Super/Sub
Transformation
Step 1: Map Strong entities
Step 2: Map Weak Entities
Step 3: Map Binary Relationship
Step 4: Map Associative Entities
STEP 5: Map Unary Relationship
Step 6: Map Ternary Relations
Step 7: Map Super/Sub
Example 1
PIANO MODEL DESIGNER
Serial Number ID Number Designer ID
Mfg Completion Date Name Designer Name
Mfg Completion Date
Serial Number
PIANO
Quality Grade
Inspection Date
2
Employee Number
TECHNICIAN
TECHNICIAN
Employee Number
Supervises
Example 2
INTEGRITY CONSTRAINTS
Integrity Constraints
Data Integrity refers to the
correctness and consistency of
stored data
Integrity constraints are the
rules(Business rules) that the database
users are not permitted to violate
Integrity Constraints
Common type of integrity constraints
are:
1. Domain Constraints
2. Entity Integrity (Primary Key Rule)
3. Referential Integrity (Foreign Key Rule)
4. General Constraints (Business Rules)
Domain Constraints
All of the values that appear in a column of a relation
must be from the same domain.
A domain is the set of values that may be assigned to
an attribute.
A domain definition usually consists of the following
components:
domain name,
meaning,
data type,
size (or length),
allowable values or allowable range (if applicable).
Integrity Constraints
Entity Integrity
This rule applies on the primary key
attribute of a relation
According to the Entity integrity rule,
Primary Key should be unique
no primary key attribute( or component
of a primary key attribute) can be Null
Referential Integrity
Association between the tables are
defined using the foreign keys
Referential Integrity is a constraint
on foreign key values
Either the foreign the value must
match with the primary key of its
home relation or it must be
completely Null
Integrity Constraints
General Constraints
General constraints are the
restrictions that are expressible only
as arbitrary predicates about the data
Suppose in university database no
class may be scheduled for room H221
after 2 P.M
CUSTOMER
ORDER LINE
Order_ID Product_ID Quantity
PRODUCT