D87e9chapter 2
D87e9chapter 2
D87e9chapter 2
Employee
Has
Dependents
Employee
Manages
Employee
Works for
Department
Ternary Relationship: A ternary relationship involves three entities and is used when a
binary relationship is inadequate. Many modeling approaches recognize only binary
relationships. Ternary or n-ary relationships are decomposed into two or more binary
relationships.
P1
C1
P2
C2
P3
C3
P4
C4
PERSON
CHAIR
Figure 8 : One to One
instance of entity B, there is only one instance of entity A. For example a department has
many employees or each employee is assigned to one department.
E1
O1
E2
E3
O2
E4
O3
E5
ORGANIZATION
EMPLOYEE
Figure 9 : One to Many
D1
E1
E2
D2
E3
D3
E4
E5
EMPLOYEE
DEPARTMENT
Figure 10 : Many to one
S1
C1
S2
C2
S3
C3
S4
C4
STUDENT
COURSE
Figure 11: Many to many
ER Notations for Cardinality: An entity may be associated with one, none, or many
occurrences of another entity. In ER diagrams, the types of relationships are represented
as follows:
Customer
Have
Account
Advisor
Student
Advise
Student
Course
Take
Head of
Employee
Partial participation
Department
Total participation
Attribute of a relationship: These attributes best describe the relationship rather than
any individual entity
Medicine
No. of Days
Dosage
Prescription
Doctor
Patient
Subclass: A subgroup an entity type which has attributes that are distinct from
those in other subgroups
Superclass: An generic entity type that has a relationship with one or more
subclasses
Inheritance
a. Subclass entities inherit values of all attributes of the superclass
b. An instance of a subclass is also an instance of the superclass
SECERATRY
ENGINEER
TEHCNICIAN
Each of these employee types is described by a set of attributes that includes all the
attributes of entity set employee plus possibly additional attributes. For example,
SECERATRY entities my be described further by the attribute TypingSpeed, whereas
TECHNICIAN entities may be described further by the attribute Tgrade and ENGINEER
entities may be described by EngType. The processof designating subgroupings within
an entity set is called specialization. The specialization of EMPLOYEE allow us to
distinguish among EMPLOYEES according to whether they are SECERATRY,
TECHNICIAN or ENGINEER.
We call each of these subgrouping a subclass of the EMPLOYEE entity type, and the
EMPLOYEE entity type is called the superclass for each of these subclasses. In terms of
E-R diagram, specialization is depicted by a triangle component labeled ISA. The label
ISA stands for is a and represents, for example, that a customer is a person. The ISA
relationship can also be referred as superclass-subclass relationship.
NoOfAxles
NoOfPassengers
Price
Tonnage
Price
MaxSpeed
VehicleId
TRUCK
K
CAR
LicencePlacte No.
VehicleId
LicencePlacte No.
Figure 22(a)
Price
LicencePlacteNo
VehicleId
VEHICLE
ISA
MaxSpeed
Tonnage
NoOfPasseng
ers
NoOfAxle
s
CAR
TRUCK
Figure 22 : Specialization
Birthdate
Employeei
d
Address
Name
JobType
EMPLOYEE
ISA
TypingSpeed
SECRETARY
EngType
TGrade
TECHNICIAN
ENGINEER
EMPLOYEE
ISA
CLASSIFIED
WAGES
Completeness constraint
The third constraint on specialization is called the completeness constraint, which may
be total or partial.
PERSON
ISA
FACULTY
STAFF
STUDENT
ISA
HOURLY_EMPLOYEE
SALARIED_EMPLOYEE
AGGREGATION
The E-R model has one limitation that it is not possible to express relationships among
relationships. In such situations we use aggregation. Aggregation, is an approach of
modeling a relationship set as a higher level entity set or, in other words, aggregation
helps to model the participation of one relationship set into other relationship set. For
example, consider publisher database in which an author writes a particular book and a
publisher publishes the book on a specific date written by a particular author. To model
the situation, an E-R diagram is shown in fig. 25.
Author
Write
Book
Publish
Works_For
Publisher
The situation is modelled by associating publisher with entity set author and book
through a relationship publish as shown in fig. 25. But this model produces redundant
information since every author-book pair in publish is also in writes so better method
to model the situation is aggregation. Aggregation is an abstraction through which
relationships are treated as higher level entities. We can treat the relationships set writes
along with the entity sets author and Book as a higher level entity set called author-book
as shown in fig. 26.
Author
Write
Book
Publish
Publisher
Steps in ER Modeling
Step 1: Identify the Entities
Step 2: Find the relationships
Step 3: Identify the key attributes
Step 4: Identify other relevant attributes
Step 5: Draw complete E-R diagram with all attributes including Primary Key
Case Study 1 : ER Model For a college Database
Assumptions :
A college contains many departments
Each department can offer any number of courses
Many instructors can work in a department
An instructor can work only in one department
For each department there is a Head
An instructor can be head of only one department
Each instructor can take any number of courses
A course can be taken by only one instructor
A student can enroll for any number of courses
Each course can have any number of students
Figure 27
Case Study2 Banking Business Scenario
Assumptions :
There are multiple banks and each bank has many branches.
Each branch has multiple customers
Customers have various types of accounts
Some Customers also had taken different types of loans from these bank
branches
One customer can have multiple accounts and Loans
Figure 28
Floor
Street
Building
Date of
Joining
Address
Years of
Service
Name
Employee
E#
Skillset
Binary (M:N) : A new table is created to represent the relationship. The new table
contains two foreign keys- one from each of the participating entities. The primary key
of the new table is the combination of the two foreign keys.
Unary (1:1) : In unary 1:1 relationship the primary key field itself will become foreign
key in the same table.
Medicine
No. of Days
Dosage
Doctor
Prescription
Patient
E#
Ename
DOB
Address
EMPLOYEE
ISA
BasicSal
NoOfHrs
HOURLY_EMPLOYEE
SALARIED_EMPLOYEE
EMPLOYEE
E#
PK
Ename
DOB
Address
HOURL_EMPLOYEE
E#
PK
NoOfHrs
SALARAIED_EMPLOYEE
E#
PK
BasicSal
Figure 50 Conversion of specialization to table
Converting Aggregation
If an aggregated entity set combines two entity sets with one relationship and this
aggregated entity set is related with one more entity than
2. Similarly a Bank table can be created with Bank Bankcode, Name and
Address columns
BANK (BankCode, Name, Address)
3. Weak Entity types are converted into a table of their own, with the primary key
of the strong Entity acting as a foreign key in the table. This Foreign key along
with the key of the Weak Entity form the composite primary key of this table.As
per this guideline, a Branch table can be created with the following structure.
BRANCH (BankCode, Branch#, Name, Address)
4. Each relationship can be defined as separate table in relational schema. Key
attributes of participating entities will become key attribute of the Relationship.
We can define Loan_Detail table with Loan# and Customer# together as
primary key with other relevant attributes like DateOfSanction, InterestRate,
LoanAmount, Duration etc.
LOAN_DETAILS (Loan#, Customer#, DateofSanction, InterestRate,
LoanAmount, Duration)
5. In a Many to Many relationship, it is necessary to create separate tables for
participating entities and relationships. In the banking application we have
Customer and Loan Entities have a Many to Many relationship. Hence one
should create separate tables for
CUSTOMER
LOANS
LOAN_DETAILS.