+ All Categories
Home > Documents > Fundamentals/ICY: Databases 2010/11 WEEK 5

Fundamentals/ICY: Databases 2010/11 WEEK 5

Date post: 12-Jan-2016
Category:
Upload: lemuel
View: 25 times
Download: 0 times
Share this document with a friend
Description:
Fundamentals/ICY: Databases 2010/11 WEEK 5. John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham, UK. Mental Exercises for You. What about the Employments bridging type we introduced? - PowerPoint PPT Presentation
Popular Tags:
42
Fundamentals/ICY: Databases 2010/11 WEEK 5 John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham, UK
Transcript
Page 1: Fundamentals/ICY: Databases 2010/11 WEEK 5

Fundamentals/ICY: Databases2010/11

WEEK 5

John BarndenProfessor of Artificial Intelligence

School of Computer ScienceUniversity of Birmingham, UK

Page 2: Fundamentals/ICY: Databases 2010/11 WEEK 5

Mental Exercises for You What about the Employments bridging type we

introduced?

One entity type can be existence-dependent on another without therefore being weak. Why?

Page 3: Fundamentals/ICY: Databases 2010/11 WEEK 5

New for Week 5

Page 4: Fundamentals/ICY: Databases 2010/11 WEEK 5

Entity Relationship (ER) Model(s) and Diagrams

Page 5: Fundamentals/ICY: Databases 2010/11 WEEK 5

Rob, Coronel & Crockett

Database Systems: Design, Implementation, and Management,

(2008)

Uses different diagrams from main book and my slides!

More like the notation in the Additional Notes

Page 6: Fundamentals/ICY: Databases 2010/11 WEEK 5

The Entity Relationship Model Introduced by Chen in 1976

Most widely used “conceptual model” of DBs.

“The ER model” : general meaning = just the idea of thinking of things as composed of entities, attributes and relationships.

We also say that applying this approach in a particular case gives rise to an “ER model” of the specific environment of interest.

Diagrams based on the/a model are a widely accepted and adopted graphical approach to database design.

The//an ER model has nothing intrinsically to do with diagrams!!! Let alone any specific sort of diagram!!!

Page 7: Fundamentals/ICY: Databases 2010/11 WEEK 5

A Conceptual Model

ER model that provides high-level, manager//user-friendly view of the database

Basis for identification and description of main data objects and relationships, avoiding details

Page 8: Fundamentals/ICY: Databases 2010/11 WEEK 5

Entity Relationship Diagrams (ERDs) An ER model of an environment forms the basis of an ER

diagram (ERD) or several ERDs.

There are several markedly different styles of ERD, and for each main style there are several variants.

And the style in the module handouts will differ somewhat from that in the textbooks and these lectures

An ERD depicts (some of) the ER model’s entity types, attributes and relationships, and (depending on the diagram style) varying amounts of other info such as connectivities, cardinalities, keys, weakness, …

Page 9: Fundamentals/ICY: Databases 2010/11 WEEK 5

Quick Flavour of Two Styles of Diagram

Page 10: Fundamentals/ICY: Databases 2010/11 WEEK 5

The Completed Tiny College ERD

Page 11: Fundamentals/ICY: Databases 2010/11 WEEK 5

Relationships: The Basic Chen ERD-let

Page 12: Fundamentals/ICY: Databases 2010/11 WEEK 5

Relationships: The Basic Crow’s Foot ERD-let

Page 13: Fundamentals/ICY: Databases 2010/11 WEEK 5

Caution In previous two diagrams, each relationship was

mandatory in both directions.

But saying “1:1”, “1:M” or “M:N” does not of itself imply mandatoriness in either direction. In particular, don’t be deceived by the “1” here – it’s not a minimum.

We will see in a minute how to draw optional (non-mandatory) relationships.

Page 14: Fundamentals/ICY: Databases 2010/11 WEEK 5

A Model for Tiny College

Page 15: Fundamentals/ICY: Databases 2010/11 WEEK 5

1:1 Relationship Between PROFESSOR and DEPARTMENT(mandatory in both directions)

Page 16: Fundamentals/ICY: Databases 2010/11 WEEK 5

1:M Relationship Between PAINTER and PAINTING (mandatory in both directions)

Page 17: Fundamentals/ICY: Databases 2010/11 WEEK 5

Tables for that 1:M Relationship

Page 18: Fundamentals/ICY: Databases 2010/11 WEEK 5

M:N Relationship between STUDENT and CLASS (both ways mandatory):preliminary ERD (conceptual level)

Page 19: Fundamentals/ICY: Databases 2010/11 WEEK 5

Conversion to Two 1:M Relationships (towards “logical” level)

Page 20: Fundamentals/ICY: Databases 2010/11 WEEK 5

A Bridge (or Composite) Entity Type

Its table is called a linking table (or bridging table)

Its primary key is composed of the primary keys of each of the entity types to be connected

Those keys are also foreign keys in the bridge type

Linking table may contain multiple occurrences of each foreign key value

May also contain additional attributes that play no role in the bridging as such

Page 21: Fundamentals/ICY: Databases 2010/11 WEEK 5

Direct Impln of M:N Relationship between STUDENT and CLASS

Page 22: Fundamentals/ICY: Databases 2010/11 WEEK 5

Converting the M:N Relationship into Two 1:M Relationships

Page 23: Fundamentals/ICY: Databases 2010/11 WEEK 5

Connectivity and Cardinality in an ERD

Page 24: Fundamentals/ICY: Databases 2010/11 WEEK 5

Relationship Participation Optional [in a particular direction, X to Y]:

an X entity occurrence does not require a corresponding Y entity occurrence

i.e. the minimum number of Ys per X is 0

Mandatory [in a particular direction, X to Y]:

an X entity occurrence requires a corresponding Y entity occurrence

i.e. the minimum number of Ys per X is 1 or more

Page 25: Fundamentals/ICY: Databases 2010/11 WEEK 5

Drawing Optionality

NOTE: the dashing of the line is NOT because of the optionality, but because of weakness

Page 26: Fundamentals/ICY: Databases 2010/11 WEEK 5

The Chen Representation of the Invoicing Problem

Page 27: Fundamentals/ICY: Databases 2010/11 WEEK 5

The Crow’s Foot Representation of the Invoicing Problem

Page 28: Fundamentals/ICY: Databases 2010/11 WEEK 5

The Attributes of the STUDENT Entity

Page 29: Fundamentals/ICY: Databases 2010/11 WEEK 5

Attributes

Page 30: Fundamentals/ICY: Databases 2010/11 WEEK 5

Weak Entity Types in ERDs

Page 31: Fundamentals/ICY: Databases 2010/11 WEEK 5

A Weak Entity in an ERD

Page 32: Fundamentals/ICY: Databases 2010/11 WEEK 5

A Weak (Non-Identifying) Relationship

Page 33: Fundamentals/ICY: Databases 2010/11 WEEK 5

Multivalued Attributes in ERMs and ERDs

(now with more explanation)

Page 34: Fundamentals/ICY: Databases 2010/11 WEEK 5

A Multivalued Attribute in an Entity:CAR_COLOR gives multiple colours

Page 35: Fundamentals/ICY: Databases 2010/11 WEEK 5

Multivalued Attributes

“You should not implement them in the relational DBMS” [rather, you should re-represent them in a special way – J.A.B.]

One possibility: Use a variable-length string for the attribute, and list all the values within the string.

  Disadvantage: little support supplied by the DBMS – insertions and deletion require special extra programming. Similarly if calculations are needed on the individual values.

Page 36: Fundamentals/ICY: Databases 2010/11 WEEK 5

Multivalued Attributes, contd Another possibility: Within original entity type,

split the attribute into several different attributes corresponding to different natural components of the entity. (See next slide.)

Page 37: Fundamentals/ICY: Databases 2010/11 WEEK 5

Splitting the Multivalued Attribute into New Naturally Namable Attributes

Page 38: Fundamentals/ICY: Databases 2010/11 WEEK 5

Multivalued Attributes, contd

Disadvantages: The attribute may need to be split differently for different

entities. The attribute may not have naturally namable aspects at all.  E.g., imagine blotches of colour in random places on a car.

Page 39: Fundamentals/ICY: Databases 2010/11 WEEK 5

Multivalued Attribute Problems, contd Another possibility: Within original entity type, split

the attribute into several different attributes not corresponding to specific components of the entity. E.g., have attributes called Colour1, Colour2, … , Colour6.

Advantage: copes with the no-identifiable-components problem and the different-split problems. NB: also allows repetition of colours.

Disadvantages:   Have to set aside enough columns to accommodate the

conceivable max, but if this max not often approached then have a lot of wasted space.

  Searching for a colour, or doing insertions and deletions, can be very cumbersome.

Page 40: Fundamentals/ICY: Databases 2010/11 WEEK 5

Multivalued Attributes, contd Often Better: Replace the attribute by a new 1:M

relationship to a new entity type holding the original attribute’s data.

If the components of the original attribute are conceptually distinguishable in a natural way, the new entity can have an attribute whose values identify those components.

Page 41: Fundamentals/ICY: Databases 2010/11 WEEK 5
Page 42: Fundamentals/ICY: Databases 2010/11 WEEK 5

Multivalued Attributes, contd If the original multivalued attribute does not have

namable components, leave out the component-naming attribute (COL_SECTION in diagram).

But NB: the PK would then need to include, in our example, the colour. So we can’t have repetitions of colours.

Or include an integer-valued attribute to allow the values to be distinguished.

The PK now includes that attribute. Now we can have repetitions of colours.


Recommended