EntityRelationship Modelling Entity and relationship sets Issues for

  • Slides: 24
Download presentation
Entity-Relationship Modelling Entity and relationship sets Issues for object-based modelling 9/15/2020 1 CS 319

Entity-Relationship Modelling Entity and relationship sets Issues for object-based modelling 9/15/2020 1 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 1 Designing a database = real-world modelling query reflects a

The Entity-Relationship (E-R) Model 1 Designing a database = real-world modelling query reflects a real-world situation (e. g. loan status of a book) entity-relationship model of an enterprise reflects its overall logical structure entity = object that exists and is distinguishable from other objects 9/15/2020 2 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 2 … entity = object that exists and is distinguishable

The Entity-Relationship (E-R) Model 2 … entity = object that exists and is distinguishable from other objects cf OOP object doesn't "exist" until an instance is created entity can be abstract or concrete person, book abstract marriage, journey NB abstract used here not as in OO class abstraction 9/15/2020 3 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 3 Entity sets entity set = set of entities of

The Entity-Relationship (E-R) Model 3 Entity sets entity set = set of entities of the same type e. g. entity set customer = all persons having an account at bank entity sets can intersect e. g. person / customer / employee 9/15/2020 4 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 4 Entity is represented by a set of attributes e.

The Entity-Relationship (E-R) Model 4 Entity is represented by a set of attributes e. g. customer has c-name, ss#, street, c-city Representation for a particular customer { (name, Brill), (ss#, 121 -21 -2121), (street, Putnam), (city, San Marcos) } permissible values for each attribute define its domain 9/15/2020 5 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 5 entity set variable entity type definition Sample entity sets

The Entity-Relationship (E-R) Model 5 entity set variable entity type definition Sample entity sets branch customer employee account transaction 9/15/2020 b-name, b-city, assets c-name, ss#, street, c-city e-name, phone# account#, balance transaction#, date , amount 6 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 6 Relationships relationship = association among several entities e. g.

The Entity-Relationship (E-R) Model 6 Relationships relationship = association among several entities e. g. a relationship associates Brill with account 183 NB refer to this association as a relationship cf mathematical relation { (a, b, . . . , z) | aÎA, bÎB, . . , zÎZ } relationship set = math relation on 2 or more entity sets 9/15/2020 7 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 7 … relationship set = math relation on 2 or

The Entity-Relationship (E-R) Model 7 … relationship set = math relation on 2 or more entity sets binary relationship if involves two entity sets e. g. Cust. Acc [ = has (customer, account) ]. . . relationship set contains (Brill, 183). . . can have descriptive attributes associated with a relationship: e. g. last-access-date on Cust. Acc ordering in a relationship may be significant: cf. Works. For on employees. refer to role to distinguish when domain doesn't 9/15/2020 8 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 8 How to devise E-R model? … no fixed rules:

The Entity-Relationship (E-R) Model 8 How to devise E-R model? … no fixed rules: choice of relationship sets reflects real-world semantics Compare with employee: phone: telrel e-name, ss#, phone# e-name, ss# phone#, location = uses (employee, phone) Issues • does every employee have a phone? • do employees have access to many phones? • do employees share phones? 9/15/2020 9 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 9 How to devise E-R model? What is entity /

The Entity-Relationship (E-R) Model 9 How to devise E-R model? What is entity / attribute set. . . ? No easy answer: depends on structure of the enterprise Cf employee: e-name, ss#, phone# does not acknowledge employees without phones Could associate e-name with independent entity where employee e-name, ss# 9/15/2020 10 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 10 Mapping cardinalities 1 -1 [Cust. Acc = has (customer,

The Entity-Relationship (E-R) Model 10 Mapping cardinalities 1 -1 [Cust. Acc = has (customer, account)] each customer has exactly one account no joint accounts 1 -many a customer can have more than one account no joint accounts many-1 every customer has exactly one account, possibly a joint account many-many a customer can have more than one account, can also have joint accounts 9/15/2020 11 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 11 Existence dependencies Can have an entity that exists only

The Entity-Relationship (E-R) Model 11 Existence dependencies Can have an entity that exists only if another entity exists e. g. a transaction on an account delete account delete transactions from log but not v. v. existence of x depends on existence of y y dominant entity, x subordinate entity 9/15/2020 12 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 12 The notion of identity … keys for entities and

The Entity-Relationship (E-R) Model 12 The notion of identity … keys for entities and relationships "from a db perspective” difference between individual entites & relationships must be expressed in terms of their attributes cf observing objects in different states that happen to coincide "from time to time" 9/15/2020 13 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 13 The notion of identity. . . … keys for

The Entity-Relationship (E-R) Model 13 The notion of identity. . . … keys for entities and relationships superkey = set of attributes that (taken together) identify an entity e. g. ss# or {ss#, c-name} for a customer but not c-name alone. . . 2 people can have the same name, but not same social security number 9/15/2020 14 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 14 The notion of identity superkey without extra attributes is

The Entity-Relationship (E-R) Model 14 The notion of identity superkey without extra attributes is a candidate key = set of attributes that identifies an entity and is minimal wrt this property normally select a special key from the candidate keys as means to identify entity: call this the primary key 9/15/2020 15 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 15 Strong vs weak entity sets an entity set with

The Entity-Relationship (E-R) Model 15 Strong vs weak entity sets an entity set with enough attributes to make a candidate key is a strong entity set an entity set that doesn't have enough attributes to make a candidate key is a weak entity set e. g. transaction#, date, amount may coincide on two separate accounts weak entity sets are existence dependent on strong entity sets e. g. transaction on account 9/15/2020 16 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 16 weak entity sets are existence dependent on strong entity

The Entity-Relationship (E-R) Model 16 weak entity sets are existence dependent on strong entity sets. . . i. e where there is a weak entity set "there must be something around that can distinguish conceptually different entities" To distinguish entities in weak entity sets: 1. identify the strong entity set on which it is existence dependent, 2. find an attribute that will discriminate between entities in the weak entity set if the strong entity is known. For example: (account#, transaction#) transaction. 9/15/2020 17 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 17 Keys for relationships Keys distinguish entities in entity sets

The Entity-Relationship (E-R) Model 17 Keys for relationships Keys distinguish entities in entity sets … what about relationships? A key for a relationship is derived from keys for its constituent entity sets. For instance, if R(A, B, . . . , Z) is a relationship set a key for R is “a piece of info about one or more of the entities participating in a relationship in R that is sufficient to identify the relationship entirely " 9/15/2020 18 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 18 Keys for relationships …. To construct a key for

The Entity-Relationship (E-R) Model 18 Keys for relationships …. To construct a key for a relationship take union of the sets of attributes primary_key(A), primary_key(B), . . . , primary_key(Z), desc. Attr(R) and prune via functional dependency. 9/15/2020 19 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 19 Illustrating key construction e. g. R=Cust. Acc gives attribute(R)

The Entity-Relationship (E-R) Model 19 Illustrating key construction e. g. R=Cust. Acc gives attribute(R) = {ss#, account#, date} Cust. Acc many-1 candidate key is ss#. . . customer has at most one account & the date associated with this account is uniquely spec by account# If Cust. Acc many-many need {ss#, account#} as key. 9/15/2020 20 CS 319 Theory of Databases

The Entity-Relationship (E-R) Model 21 Illustrating key construction In general: add such attributes from

The Entity-Relationship (E-R) Model 21 Illustrating key construction In general: add such attributes from desc. Attr(R) as can't infer via functional dependency e. g. Cust. Banker relationship has ROLE field: loan officer / personal banker can't infer which role banker plays for a customer and hence must add ROLE attribute to the key 9/15/2020 21 CS 319 Theory of Databases

Issues for object-based modelling 1 criterion What is an entity? can a relationship be

Issues for object-based modelling 1 criterion What is an entity? can a relationship be entity? identity how to tell the difference between entities? effect of evolution of entity on identity? relationships what connections are there between entities? 9/15/2020 22 CS 319 Theory of Databases

Issues for object-based modelling 2 relationships what connections are there between entities? existence dynamic

Issues for object-based modelling 2 relationships what connections are there between entities? existence dynamic vs static instantiation dependencies existence and functional multiple views what is whole of an entity? can we circumscribe its set of attributes? 9/15/2020 23 CS 319 Theory of Databases

Issues for object-based modelling 3 behaviour do entities have state and behaviour? time do

Issues for object-based modelling 3 behaviour do entities have state and behaviour? time do entities change, or just come and go? hierarchy inheritance, classification Note: entity-relationship modelling, object-oriented modelling, network and relational database design all address these issues in quite different ways. 9/15/2020 24 CS 319 Theory of Databases