Top Banner
The Relational Data Model Database Model (ODL, E/R) Relational Schema Physi cal stora ge ODL definitions Diagrams (E/R) Tables: row names: attributes rows: tuples Complex file organization and index structures.
23

The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Dec 23, 2015

Download

Documents

Randall Parsons
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

The Relational Data ModelDatabase Model(ODL, E/R)

Relational Schema

Physicalstorage

ODL definitions

Diagrams (E/R)

Tables: row names: attributes rows: tuples

Complexfile organizationand index structures.

Page 2: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Terminology

Name Price Category Manufacturer

gizmo $19.99 gadgets GizmoWorks

Power gizmo $29.99 gadgets GizmoWorks

SingleTouch $149.99 photography Canon

MultiTouch $203.99 household Hitachi

tuples

Attribute names

Page 3: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

More Terminology

Every attribute has an atomic type.

Relation Schema: relation name + attribute names + attribute types

Relation instance: a set of tuples. Only one copy of any tuple!

Database Schema: a set of relation schemas.

Database instance: a relation instance for every relation in the schema.

Page 4: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

More on Tuples

Formally, a mapping from attribute names to (correctly typed) values:

name gizmo price $19.99 category gadgets manufacturer GizmoWorks

Sometimes we refer to a tuple by itself: (note order of attributes)

(gizmo, $19.99, gadgets, GizmoWorks) or

Product (gizmo, $19.99, gadgets, GizmoWorks).

Page 5: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Updates

The database maintains a current database state.

Updates to the data:

1) add a tuple 2) delete a tuple 3) modify an attribute in a tuple

Updates to the data happen very frequently.

Updates to the schema: relatively rare. Rather painful.

Page 6: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

From ODL to Relational Schema

Start simple: a class definition has only single valued attributes

Interface product{ float price; string name; Enum {telephony, gadgets, books} category}

Every attribute becomes a relation attribute:

Name Price Category

Gizmo $19.99 gadgets

Page 7: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Adding Non atomic Attributes

Name Currency Amount Category

Gizmo US$ 19.99 gadgets

Power Gizmo US$ 29.99 gadgets

Price is a record: {string currency, float amount}

Page 8: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Set Attributes

Name SSN Phone Number

Fred 123-321-99 (201) 555-1234

Fred 123-321-99 (206) 572-4312Joe 909-438-44 (908) 464-0028Joe 909-438-44 (212) 555-4000

One option: have a tuple for every value in the set:

Disadvantages?

Page 9: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Modeling Collection Types

How can we model bags?

Lists?

Fixed length arrays?

The problem becomes even more significant if a class has several attributes that are set types? Question: how bad is the redundancy for n set type attributes, each with possibly up to m values?

Questions:

Page 10: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Modeling RelationshipsInterface Product { attribute string name;

attribute float price; relationship <Company> madeBy; }Interface Company {

attribute string name; attribute float stock-price; attribute string address;

} How do we incorporate the relationship madeBy into the schema?

Page 11: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Option #1 Name Price made-by-name made-by-stock-price made-by-address

Gizmo $19.99 gizmoWorks 0.0001$ Montezuma

What’s wrong?

Page 12: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

HintInterface Product { attribute string name;

attribute float price; relationship <Company> madeBy; }Interface Company {

attribute string name; attribute float stock-price; attribute string address; relationship set <Product> makes; }

Page 13: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Better Solution

Name Price made-by-name

Gizmo $19.99 gizmoWorks

Product relation: (assume: name is a key for company)

Company relation:

Name Stock Price Address

Gizmo $0.00001 Montezuma

Page 14: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Additional Issues

1. What if there is no key?

2. What if the relationship is multi-valued?

3. How do we represent a relationship and its inverse?

Page 15: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

From E/R Diagrams to Relational Schema

Easier than ODL (using a liberal interpretation of the word “easy”)

- relationships are already independent entities

- only atomic types exist in the E/R model.

Entity sets relations

Relationships relations

Special care for weak entity sets.

Page 16: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

address name ssn

Person

buys

makes

employs

CompanyProduct

name category

Stock price

name

price

Page 17: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Entity Sets to Relations

Product

name category

price

Product:

Name Category Price

gizmo gadgets $19.99

Page 18: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Relationships to Relations

makes CompanyProduct

name category

Stock price

name

Relation MAKES (watch out for attribute name conflicts)

Product-name Product-Category Company-name Starting-year

gizmo gadgets gizmoWorks 1963

Start Year

Page 19: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Handling Weak Entity Sets

UniversityTeam affiliation

numbersport name

Relation TEAM:

Sport Number University-name

mud wrestling 15 Montezuma State U.

- need all the attributes that contribute to the key of Team - don’t need a separate relation for Affiliation.

Page 20: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Modeling Subclass Structure

Product

Educational Product

Educ-softwareProduct

Software Product

ageGrouptopic

Platformsrequired memory

Educational-method

Page 21: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Option #1: the ODL Approach

4 tables: each object can only belong to a single class

Product(name, price, category, manufacturer)

EducationalProduct( name, price, category, manufacturer, ageGroup, topic)

SoftwareProduct( name, price, category, manufacturer, platforms, requiredMemory)

EducationalSoftwareProduct( name, price, category, manufacturer, ageGroup, topic, platforms, requiredMemory)

Page 22: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Option #2: the E/R Approach

Product(name, price, category, manufacturer)

EducationalProduct( name, ageGroup, topic)

SoftwareProduct( name, platforms, requiredMemory)

No need for a relation EducationalSoftwareProduct

Unless, it has a specialized attribute: EducationalSoftwareProduct(name, educational-method)

Page 23: The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:

Option #3: The Null Value Approach

Have one table:

Product ( name, price, manufacturer, age-group, topic, platforms, required-memory, educational-method)

Some values in the table will be NULL, meaning that the attribute not make sense for the specific product.

How many more meanings will NULL have??