Professional Documents
Culture Documents
Modeling
' database can $e modeled as: a collection o" entities( relationship among entities) 'n entity is an o$*ect that e ists and is distinguisha$le "rom other o$*ects)
Entity Sets customer and loan_ loan customer_id customer_ customer_ customer_ amount
name street city number
Relationship Sets
' relationship is an association among se+eral entities E ample: ,ayes customer entity depositor relationship set '--./ account entity
' relationship set is a mathematical relation among n / entities( each taken "rom entity sets 01e-( e/( 2 en3 4 e- E-( e/ E/( 2( en En5 6here 1e-( e/( 2( en3 is a relationship E ample: 1,ayes( '--./3 depositor
Example: Suppose employees of a bank may have jobs (responsibilities) at multiple branches, with different jobs at different branches. Then there is a ternary relationship set between entity sets employee, job, and branch
Relationships $et6een more than t6o entity sets are rare) Most relationships are $inary) 1More on this later)3
'ttri$utes
'n entity is represented $y a set o" attri$utes( that is descripti+e properties possessed $y all mem$ers o" an entity set)
Example:
Domain 8 the set o" permitted +alues "or each attri$ute 'ttri$ute types: Simple and composite attri$utes) Single-valued and multi-valued attri$utes E ample: multi+alued attri$ute: phone_numbers Derived attri$utes Can $e computed "rom other attri$utes E ample: age( gi+en date9o"9$irth
Composite 'ttri$utes
Mapping Cardinalities
One to one
One to many
Note: Some elements in A and B may not be mapped to any elements in the other set
Mapping Cardinalities
Many to one
Many to many
Note: Some elements in A and B may not be mapped to any elements in the other set
;eys
' super key o" an entity set is a set o" one or more attri$utes 6hose +alues uni<uely determine each entity) ' candidate key o" an entity set is a minimal super key Customer_id is candidate key o" customer account_number is candidate key o" account 'lthough se+eral candidate keys may e ist( one o" the candidate keys is selected to $e the primary key)
E-R Diagrams
Rectangles represent entity sets. Diamonds represent relationship sets. Lines link attributes to entity sets and entity sets to relationship sets. Ellipses represent attributes
Double ellipses represent multivalued attributes. Dashed ellipses denote derived attributes.
Roles
Entity sets o" a relationship need not $e distinct =he la$els ?manager@ and ?6orker@ are called rolesA they speci"y ho6 employee entities interact +ia the 6orks9"or relationship set) Roles are indicated in E-R diagrams $y la$eling the lines that connect diamonds to rectangles) Role la$els are optional( and are used to clari"y semantics o" the relationship
Cardinality Constraints
We e press cardinality constraints $y dra6ing either a directed line 13( signi"ying ?one(@ or an undirected line 1B3( signi"ying ?many(@ $et6een the relationship set and the entity set) :ne-to-one relationship: ' customer is associated 6ith at most one loan +ia the relationship borrower ' loan is associated 6ith at most one customer +ia borrower
:ne-=o-Many Relationship
In the one-to-many relationship a loan is associated 6ith at most one customer +ia borrower( a customer is associated 6ith se+eral 1including .3 loans +ia borrower
Many-=o-:ne Relationships
In a many-to-one relationship a loan is associated 6ith se+eral 1including .3 customers +ia borrower( a customer is associated 6ith at most one loan +ia borrower
Many-=o-Many Relationship
' customer is associated 6ith se+eral 1possi$ly .3 loans +ia $orro6er ' loan is associated 6ith se+eral 1possi$ly .3 customers +ia $orro6er
E-R
Design Issues
Use of entity sets vs. attributes Choice mainly depends on the structure o" the enterprise $eing modeled( and on the semantics associated 6ith the attri$ute in <uestion) Use of entity sets vs. relationship sets Possi$le guideline is to designate a relationship set to descri$e an action that occurs $et6een entities Binary versus n-ary relationship sets 'lthough it is possi$le to replace any non$inary 1n-ary( "or n C /3 relationship set $y a num$er o" distinct $inary relationship sets( a nary relationship set sho6s more clearly that se+eral entities participate in a single relationship) Placement of relationship attributes
That is, the relationship from account to customer is many to one, or equivalently, customer to account is one to many
,o6 a$out doing an ER design interacti+ely on the $oardH Suggest an application to $e modeled)
SpecialiJation E ample
'ggregation
Consider the ternary relationship works_on, which we saw earlier Suppose we want to record managers for tasks performed by an
employee at a branch
'ggregation 1Cont)3
Relationship sets wor#s_on and manages represent o+erlapping in"ormation E+ery manages relationship corresponds to a wor#s_on relationship
,o6e+er( some wor#s_on relationships may not correspond to any manages relationships So 6e canIt discard the wor#s_on relationship Eliminate this redundancy +ia aggregation =reat relationship as an a$stract entity 'llo6s relationships $et6een relationships '$straction o" relationship into ne6 entity Without introducing redundancy( the "ollo6ing diagram represents: 'n employee 6orks on a particular *o$ at a particular $ranch 'n employee( $ranch( *o$ com$ination may ha+e an associated manager
primary key of the aggregated relationship, the primary key of the associated entity set any descriptive attributes
Schemas Corresponding to 'ggregation 1Cont)3 For example, to represent aggregation manages between
relationship works_on and entity set manager, create a schema manages (employee_id, branch_name, title, manager_name)
Schema works_on is redundant provided we are willing to store null