Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
DATABASE
ENTITY-RELATIONSHIP MODEL
ENTITY-RELATION MODEL
E-R MODEL
The Entity-Relationship (ER) model was
originally proposed by Peter in 1976
The ER model is a conceptual data model that
views the real world as entities and relationships.
A basic component of the model is the EntityRelationship diagram, which is used to visually
represent data objects.
collection of entities,
relationship among entities.
plant
holidays
Relationships
ARelationshiprepresentsanassociationbetweentwoormore
entities. Relationships are classified in terms of degree,
connectivity, cardinality, and existence. An example of a
relationshipwouldbe:
Employeesareassignedtoprojects
Projectshavesubtasks
Departmentsmanageoneormoreprojects
ATTRIBUTES
Attributes describe the properties of the entity of
which they are associated. We can classify
attributes as following:
Simple
Composite
Single-valued
Multi-valued
Derived
EXAMPLE
DEGREE OF A RELATIONSHIP
The degree of a relationship is the number of
entities associated with the relationship. The nary relationship is the general form for degree n.
Special cases are the binary, and ternary, where
the degree is 2, and 3, respectively.
CONNECTIVITY AND
CARDINALITY
The connectivity of a relationship describes the
mapping of associated entity instances in the
relationship. The values of connectivity are
"one" or "many". The cardinality of a
relationship is the actual number of related
occurrences for each of the two entities.
The basic types of connectivity for relations are:
One to One (1:1)
One to Many (1:M)
Many to One (M:1)
Many to Many (M:M)
DIRECTION
E-R NOTATION
EXAMPLE
CUSTOMER-LOAN RELATIONSHIP
EXERCISE
Consider the following database:
S (S#, SSNAME, STATUS,
CITY)
P (P#, PNAME, COLOR,
WEIGHT, CITY)
J ( J#, JNAME, CITY)
SPJ( S#, P#, J#, QTY)
Here, S indicates information of
suppliers, P Parts, J Projects
and SPJ indicates the supplied
quantity details.
TOTAL PARTICIPATION
REPRESENTATION OF
CARDINALITY IN THE E-R
DIAGRAM
The cardinality of a relationship is the actual number of
Phone_no
Address
City
Loan_No
amount
C_name
Customer
0..*
Cust_
Loan
1..1
Loan
For
Phone_no
Address
City
Loan_No
amount
C_name
Customer
0..*
Cust_
Loan
1..1
Loan
Considerthefollowingdatabase:
S(S#,SSNAME,STATUS,CITY)
P(P#,PNAME,COLOR,WEIGHT,CITY)
J(J#,JNAME,CITY)
SPJ(S#,P#,J#,QTY)
HereSindicatesinformationofsuppliers,PParts,JProjects
andSPJindicatesthesuppliedquantitydetails.
Car-insurance company
Ithasasetofcustomers,eachofwhoownsoneormorecars.
Carmayhaveanynumberofcustomers.
Each car has associated with it zero to any number of
recorded accidents. System should store date and location of
accident.
Car insurance company will pay damage amount for the
accidentalcarstoconcerneddriver.
dno
dname
loc
DEPARTMENT
heads
c_code
offers
c_name
credits
COURSE
enroll
has
teach
TEACHER
t_code
name
STUDENT
mob_no
roll_no
name
address
Theprimarykeyofaweakentitysetisformedbytheprimary
key of the strong entity set on which the weak entity set is
existencedependent,plustheweakentitysetsdiscriminator.In
the above example {loan_number, payment_number} acts as
primarykeyforpaymententityset.
Therelationshipbetweenweakentityandstrongentitysetis
calledasIdentifyingRelationship.Inexample,loan-paymentis
theidentifyingrelationshipforpaymententity.Aweakentity
setisrepresentedbydoublyoutlinedboxandcorresponding
identifyingrelationbyadoublyoutlineddiamond
CASE STUDY
Represent each of the following requirements with an ER diagram:
DESIGN ISSUES
USE OF ENTITY SETS VERSUS
ATTRIBUTES
Consider the entity set employee with attributes
The
DESIGN CONSTRAINTS ON A
SPECIALIZATION/GENERALIZAT
ION
Constraint on which entities can be members of a given
user-defined
User-defined lower-level entity sets are not constrained by a
membership condition; rather, the database user assigns
entities to a given entity set.
For instance, let us assume that, after 3 months of
employment, bank employees are assigned to one of four
work teams.
We therefore represent the teams as four lower-level entity
sets of the higher-level employee entity set.
A given employee is not assigned to a specific team entity
automatically on the basis of an explicit defining condition.
Instead, the user in charge of this decision makes the team
assignment on an individual basis. The assignment is
implemented by an operation that adds an entity to an
entity set.
Constraint
Overlapping
DESIGN CONSTRAINTS ON A
SPECIALIZATION/GENERALIZAT
ION
(CONT.)constraint -- specifies whether
Completeness
or not an entity in the higher-level entity set
must belong to at least one of the lower-level
entity sets within a generalization.
total
Aggregation
SupposeacustomerloanpairmayhaveabankempWhoisa
loanofficerforthatparticularpair.
CUST
BORROWER
LOANOFFICER
EMP
LOAN
Thebestwaytomodelthesituationistouseaggregation.
Aggregationisasnabstractionthroughwhichrelationshiparetreated
ashigherlevelentities
CUST
BORROWER
LOAN-OFFICER
EMP
LOAN
E-R DIAGRAM OF
BAKING SYSTEM