Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fundamentals/ICY: Databases 2012/13 WEEK 7 John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham, UK.

Similar presentations


Presentation on theme: "Fundamentals/ICY: Databases 2012/13 WEEK 7 John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham, UK."— Presentation transcript:

1 Fundamentals/ICY: Databases 2012/13 WEEK 7 John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham, UK

2 Reminder of Week 6

3 A Generalization Hierarchy with Overlapping Subtypes

4 Actual Realization of Subtyping A supertype maintains a 1:1 relationship with each subtype [optional in the super-to-sub direction and mandatory in the other]

5 New for Week 7

6 More-Than-Binary Relationships in ERMs and ERDs

7 Relationship Degree uBinary relationship [my definition] l Two entities (“entity occurrences”) are associated by each instance of the relationship, as in all previous examples in lecture slides. uTernary relationship [my definition] l Three entities are associated by each relationship instance. uEtc. uNB: the entities associated with each other need not be of different types. l Indeed, could have an entity (occurrence) associated with itself: e.g. an “employs” relationship where someone can employ him/herself. Doesn’t violate binarity.

8 Relationship Degree: Terminology Problems uThe standard terminology & definitions relating to “relationship degree” (see the textbook) are mathematically anomalous. uThe degree of a relationship should be the number of entities (“entity occurrences”) that are associated by each instance of the relationship, no matter how many entity types are involved. uBut the definitions used in the books count the number of entity types (“entities” in the abbreviated language used), departing from normal mathematical practice.

9 Terminology Problems contd. uA “unary” relationship is standardly defined as being a relationship where the entity occurrences are all within the same entity type (“entity”). l E.g., a “manages” relationship between employees. uA better name is “recursive” (also used in the books). l Above example is binary recursive, under my definition. uThe books define a binary relationship as one relating two different types, even when there are more than two entity occurrences per relationship instance. uSimilarly ternary and three different types.

10 Different Degrees The “unary” case is badly named. It’s really a type of binary. The word “recursive” [later] is better.

11 Caution about Next Slide uAstute members of the class noted an error in the following slide. uThe FUND table should just be descriptions of different funds, such as Heart fund, a Cancer fund, and so on. FUND_ID should be the PK. u At some point I’ll replace the example with another. For now, please see the doctor/patient/drug prescription example from the textbook, pp.337-339.

12 Tables for a Ternary Relationship CFR is just like a bridging entity type for a binary M:N relationship, but has 3 links to other types instead of 2

13 Recursive Relationships in ERMs and ERDs

14 Recursive Relationships uA recursive relationship links entities of the same type. l E.g.: marriage, management, parthood, … uCan have partial recursion: just some of the entity types involved in a relationship (that is ternary or of higher degree in my sense) could be the same.

15 Recursive Relationships: Symmetry uA relationship R between entity types E,F (possibly the same) is symmetric iff: if eRf then fRe (i.e., if R relates entity e of type E to entity f of type F, then it must also relate f to e.) E.g.: marriage, being-sibling-of. uRecursive relationships cause major redundancy problems when symmetric. uSymmetry only makes sense in the 1:1 and M:N cases. u((Can generalize the points to partly-recursive cases.))

16 An ER Representation of Recursive Relationships I don’t know why the Crow’s Ft model uses two links in each case

17 (necessarily non-symmetric) 1:M recursive: “EMPLOYEE Manages EMPLOYEE” Just a standard 1:M implementation except linking a table to itself. No redundancy problem.

18 non-symmetric M:N recursive: “PART Contains PART” The COMPONENT entity type is just a bridging type, linking PART to itself. NB: its first two columns both refer to PART’s PK but must be differently named. No redundancy problem.

19 symmetric (1:1) recursive relationship: “EMPLOYEE Married to EMPLOYEE”

20 Symmetry is the Problem uA non-symmetric 1-1 relationship would not have the problem shown on previous slide. uA symmetric M:N relationship would have a redundancy problem, whether implemented as in the 1-1 case or by a bridging table. l E.g.: being-sibling-of.

21 symmetric (1:1) recursive relationship: redundant & non-redundant implemntns 1) As previously—redundant. 2) MARRIED_V1 is just a bridging entity type: still redundant. 3) MARRIAGE together with MARPART act as a sort of bridge. Non-redundant.

22 Symmetric M:N, etc. uPrevious slide: explained and commented upon in the textbook, pp.353-355. uMethod 3 on previous slide can straightforwardly be generalized to: symmetric recursive M:N relationships (( (partially-)symmetric&recursive, etc. relationships that link more entities together, whatever the connectivity --- M:N:P, 1:1:1, M:1:P, … ))

23 Summary: Creating ERMs/ERDs uDesigning an ER model for a database is an iterative process, because, e.g.: l As you proceed, you think of new ways of conceiving what’s going on (much as in ordinary programming) l Multivalued attributes need to be re-represented eventually l M:N relationships can be included as such at an early stage, but usually need to be replaced by bridging entity types later l 1:1 relationships raise a red flag: may indicate poor design, especially when mandatory both ways. But standard in supertype/subtype representation, and natural in recursive relationships like “married-to”. l Special supertype/subtype notation needs eventually to be converted into more standard diagram notation l Conversion of ERM portions to a “Normal Form” – LATER.

24 MATHEMATICAL BACKGROUND TO TABLES

25 Mathematical “sets”: Basics uA “set” is an unordered collection of items of any sorts (people, numbers, numerals, shoes, atoms, strings of characters, databases, sets, blades of grass, …) without any duplication of items. The items are called “elements” or “members”. uS = {34, JAB, 59, UoB}, where “JAB” is a name for me and “UoB” is a name for this university, means that S is the set consisting of (exactly) the following four items: the abstract number 34, me, the abstract number 59, this university.

26 Basics, contd u{34, JAB, 59, UoB} = {UoB, 59, 34, JAB, JAB, 34} l Order of writing the members doesn’t matter; duplication in the writing doesn’t duplicate the member. uA set can be infinite (e.g., the set of all whole numbers). uA set can contain just one member (e.g. the set whose only element is your favourite pencil). Singleton set. l It’s different from the member itself..  uThere’s a set with no members at all: the “empty set”, usually notated as , but can also be written { }. l Somewhat analogous to zero, or a new committee which has no members yet. l There is only one empty set (rather than an empty set of numbers, an empty set of pencils, etc.)

27 Another Notation |> u{n | n is an integer, n > 301} = “The set of n such that n is an integer and n > 301.” (Actually, this notation is a slight simplification.) The set is the same as that denoted by, for instance,  {n | n is an integer, n  302}.


Download ppt "Fundamentals/ICY: Databases 2012/13 WEEK 7 John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham, UK."

Similar presentations


Ads by Google