Data Modeling and Relational Database Design

Electronic Presentation

20000GC13 Production 1.3 August 2002 D37098

Copyright © Oracle Corporation, 2002. All rights reserved.

Author
Patrice Daux Jeff Gallus Jan Speelpenning Technical Contributors and Reviewers Kate Heap Simmie Kastner Joni Lounsberry Satyajit Ranganathan Sunshine Salmon Stijn Vanbrabant Gabriella Varga Publishers Christine Markusic

Copyright ” Oracle Corporation, 2002. All rights reserved. This documentation contains proprietary information of Oracle International Corporation. It is provided under a license agreement containing restrictions on use and disclosure and is also protected by copyright law. Reverse engineering of the software is prohibited. If this documentation is delivered to a U.S. Government Agency of the Department of Defense, then it is delivered with Restricted Rights and the following legend is applicable: Restricted Rights Legend Use, duplication or disclosure by the Government is subject to restrictions for commercial computer software and shall be deemed to be Restricted Rights software under Federal law, as set forth in subparagraph (c) (1) (ii) of DFARS 252.227-7013, Rights in Technical Data and Computer Software (October 1988). This material or any portion of it may not be copied in any form or by any means without the express prior written permission of Oracle International Corporation. Any other copying is a violation of copyright law and may result in civil and/or criminal penalties. If this documentation is delivered to a U.S. Government Agency not within the Department of Defense, then it is delivered with ’Restricted Rights,’ as defined in FAR 52.227-14, Rights in DataGeneral, including Alternate III (June 1987). The information in this document is subject to change without notice. If you find any problems in the documentation, please report them in writing to Education Products, Oracle Corporation, 500 Oracle Parkway, Box, Redwood Shores, CA 94065. Oracle International Corporation does not warrant that this document is error-free. Oracle is a registered trademark and Oracle, SQL*Plus, SQL*Net, Oracle Developer, Oracle8i, Oracle9i, Oracle9i Designer and PL/SQL are trademarks or registered trademarks of Oracle Corporation. All other products or company names are used for identification purposes only and may be trademarks of their respective owners.

Copyright © Oracle Corporation, 2002. All rights reserved.

Introduction to Entities, Attributes, and Relationships

Copyright © Oracle Corporation, 2002. All rights reserved.

Overview

Why conceptual modeling? Introduction of the Key role players: • Entities • Attributes • Relationships

1-2

Copyright © Oracle Corporation, 2002. All rights reserved.

Why Create a Conceptual Model?

• • • • • •

It describes exactly the information needs of the business It facilitates discussion It helps to prevent mistakes, misunderstanding It forms important “ideal system” documentation It forms a sound basis for physical database design It is a very good practice with many practitioners

1-3

Copyright © Oracle Corporation, 2002. All rights reserved.

Between Dream and Reality...

1-5

Copyright © Oracle Corporation, 2002. All rights reserved.

Entity Relationship Modeling
PRICE LEVEL
# CODE * DESCRIPTION

defined by

applied to
ORGANIZATION

part of

• • • •

Models business, not implementation Is a well-established technique Has a robust syntax Results in easy-to-read diagrams…

at
TITLE MOVIE
CATEGORY AGE RATING DURATION MONOCHROME AUDIO PREVIEW

# PRODUCT CODE* * TITLE o o DESCRIPTION * * o o

o * o o o o o o o

EMAIL NAME POSTAL CODE REGION STREET TOWN TELEPHONE NUMBER CONTACT NAME CONTACT EXTENSION

parent organization o

the
GAME
* CATEGORY * MEDIUM o MINIMUM MEMOR

SUPPLIER

for
PRICE HISTORY
# EFFECTIVE DATE * PRICE * DEFAULT DAYS * OVERDUE RATE

available available as reviewed in on

# SUPPLIER CODE o EMAIL * APPROVED * REFERENCE

the source of

OTHER ORGANIZATION

PUBLICATION
# REFERENCE * TITLE o VOLUME o ISSUE o PUBLISH DATE

CATALOG
# REFERENCE o CATALOG DAT o DESCRIPTION

the holder o
CUSTOMER managed by EMPLOYEE
* POSITION * LAST NAME o FIRST NAME o OTHER INITIALS o EMAIL o * * * o * * * * o o o o o EMAIL DESIGNATION FIRST NAME LAST NAME OTHER INITIALS STREET TOWN POSTAL CODE REGION HOME PHONE WORK EXTENSION WORK PHONE PHOTOGRAPH STAFF REMARKS

the source of the source of

the manager o

of
COPY

acquired fro m

the cancellor of responsible for

responsible for

* ACQUIRE DATE * PURCHASE COST * SHELF CODE o CONDITION o CUSTOMER REMARKS ...

the holder of responsible for
MEMBERSHIP TYPE
# CODE * DESCRIPTION * DISCOUNT PERCENTAGE o STANDARD FEE

rented on reserved on

held by in in
REVIEW
# SEQUENCE * ARTICLE * HOT o AUTHOR o URL

the type o held by of

of
MEMBERSHIP

approved by

# NUMBER o TERMINATION REASON o TERMINATION DATE

the reservation for

renewed fo r cancelled by authorized by of requested against the MEMBERSHIP PERIOD requestor # START DATE o ACTUAL FEE PAID of approved by

used fo r

...although they may look rather complex at first sight

for

BOOKING
* o o o o BOOK DATE EXPIRE DATE NOTIFY DATE RESERVE DATE STAFF REMARKS

fulfilled as
RENTAL
* RENTAL DATE o STAFF REMARKS o COMPLETED

for

composed of for
RENTAL ITEM
# * * o o LINE NO RENTAL PERIOD PRICE PAID RETURN DATE STAFF REMARKS

the rental for

part of

1-7

Copyright © Oracle Corporation, 2002. All rights reserved.

Goals of Entity Relationship Modeling

• • • •

Capture all required information Information appears only once Model no information that is derivable from other information already modeled Information is in a predictable, logical place

1-8

Copyright © Oracle Corporation, 2002. All rights reserved.

Database Types
ER Model

Hierarchical Relational

Network

1-9

Copyright © Oracle Corporation, 2002. All rights reserved.

Entity

An Entity is:
– “Something” of significance to the business about which data must be known – A name for the things that you can list – Usually a noun

• •

Examples: objects, events Entities have instances

1-10

Copyright © Oracle Corporation, 2002. All rights reserved.

Entities and Instances

PERSON PRODUCT PRODUCT TYPE EMPLOYMENT CONTRACT JOB SKILL LEVEL TICKET RESERVATION PURCHASE ELECTION PRINTER PREFERENCE DOCUMENT VERSION

Mahatma Gandhi 2.5 x 35 mm copper nail nail my previous contract violinist fluent tonight: Hamlet in the Royal the CD I bought yesterday for parliament next fall … ...

1-11

Copyright © Oracle Corporation, 2002. All rights reserved.

Entities and Sets

An entity represents a set of instances that are of interest to a particular business.
JOB
manager cook waitress dish washer financial controller waiter porter piano player

1-12

Copyright © Oracle Corporation, 2002. All rights reserved.

Attribute

• • •

Also represents something of significance to the business Is a single valued property detail of an entity Is a specific piece of information that:
– – – – – Describes Quantifies Qualifies Classifies Specifies an entity

1-13

Copyright © Oracle Corporation, 2002. All rights reserved.

Attribute Examples

Entity EMPLOYEE CAR ORDER JOB TRANSACTION EMPLOYMENT CONTRACT

Attribute Family Name, Age, Shoe Size, Town of Residence, Email, ... Model, Weight, Catalog Price, … Order Date, Ship Date, … Title, Description, ... Amount, Transaction Date, … Start Date, Salary, ...

1-14

Copyright © Oracle Corporation, 2002. All rights reserved.

Relationships

• • • • •

Also represent something of significance to the business Express how entities are mutually related Always exist between two entities (or one entity twice) Always have two perspectives Are named at both ends

1-15

Copyright © Oracle Corporation, 2002. All rights reserved.

Relationship Examples

EMPLOYEES have JOBS JOBS are held by EMPLOYEES PRODUCTS are classified by a PRODUCT TYPE PRODUCT TYPE is a classification for a PRODUCT PEOPLE make TICKET RESERVATIONS TICKET RESERVATIONS are made by PEOPLE

1-16

Copyright © Oracle Corporation, 2002. All rights reserved.

Employees have Jobs
JOB EMPLOYEE
Shintaro Jill Ahmed Maria Adam waitress dish washer financial controller waiter porter piano player manager cook

Numerical observation: • • • •
1-17

All EMPLOYEES have a JOB No EMPLOYEE has more than one JOB Not all JOBS are held by an EMPLOYEE Some JOBS are held by more than one EMPLOYEE
Copyright © Oracle Corporation, 2002. All rights reserved.

Entity Representation in Diagram

During design, entities usually lead to tables.

1-18

Copyright © Oracle Corporation, 2002. All rights reserved.

ELECTION

• • • •

Drawn as a “softbox” EMPLOYEE Name singular Name inside Neither size, TICKET nor position RESERVATION ORDER has a special meaning JOB ASSIGNMENT

JOB

Attributes in Diagrams

Mandatory attribute, that is, known and available for every instance. Optional attribute, that is, unknown or unimportant to know for some instances.
EMPLOYEE Family Name * Address * o Birth Date o Shoe Size o Email JOB Title * Description o

During design, attributes lead to columns.
1-20 Copyright © Oracle Corporation, 2002. All rights reserved.

Relationship in Diagrams
An employee has exactly one job.

EMPLOYEE
has held by

JOB

Jobs are held by one or more employees held by one or more

During design, relationships lead to foreign keys.

1-21

Copyright © Oracle Corporation, 2002. All rights reserved.

Diagrams Are To Communicate

has JOB EMPLOYEE held by

1-22

Copyright © Oracle Corporation, 2002. All rights reserved.

Characteristics Of The Relationship Line

mandatory:

optional:

1-23

Copyright © Oracle Corporation, 2002. All rights reserved.

Two Perspectives

mandatory: EMPLOYEE has

optional: JOB
held by

1-24

Copyright © Oracle Corporation, 2002. All rights reserved.

One Way

mandatory:

optional: JOB
held by

EMPLOYEE has

Every EMPLOYEE has exactly one JOB

1-25

Copyright © Oracle Corporation, 2002. All rights reserved.

The Other Way

mandatory: EMPLOYEE has

optional: JOB
held by

A JOB may be held by one or more EMPLOYEES

1-26

Copyright © Oracle Corporation, 2002. All rights reserved.

Reading a Relationship End
P split into part of Q

1-27

Copyright © Oracle Corporation, 2002. All rights reserved.

Reading a Relationship End
P split into part of Q

1-28

Copyright © Oracle Corporation, 2002. All rights reserved.

Reading a Relationship End
P split into part of Q

“Each P

must be may be

split into

exactly one Q one or more Qs

1-29

Copyright © Oracle Corporation, 2002. All rights reserved.

Reading a Relationship End
P split into part of Q

“Each P may be split into one or more Qs”

1-30

Copyright © Oracle Corporation, 2002. All rights reserved.

Reading a Relationship End
P split into part of Q

“Each P may be split into one or more Qs”

1-31

Copyright © Oracle Corporation, 2002. All rights reserved.

Reading a Relationship End
P split into part of Q

“Each P may be split into one or more Qs”

“Each Q
1-32

must be may be

part of

exactly one P one or more Ps

Copyright © Oracle Corporation, 2002. All rights reserved.

Reading a Relationship End
P split into part of Q

“Each P may be split into one or more Qs”

“Each Q must be part of exactly one P”
1-33 Copyright © Oracle Corporation, 2002. All rights reserved.

Functions Drive Data

Business functions are always present.
– Explicit – Assumed

• •

Business functions need data. An entity, attribute, or relationship may be modeled because:
– It is used by a business function. – The business need may arise in the near future.

1-34

Copyright © Oracle Corporation, 2002. All rights reserved.

Weather Forecast
January 26 København Bremen Berlin München Amsterdam Bruxelles Paris Bordeaux
****

1/-5 0/-3 3/-1 5/-3 8/3 4/0 4/1 7/2

3 4 3 3 4 2 3 3

1-35

Copyright © Oracle Corporation, 2002. All rights reserved.

DK IR UK NL
Bremen Amsterda m

København (Copenhagen)

BE Bruxelle DE
(Brussels) s

Berli n

LU
Paris

München (Munich)

FR
Bordeaux

CH IT

1-36

Copyright © Oracle Corporation, 2002. All rights reserved.

Weather Forecast, a Solution
CITY * Name o Geographical Position subject of referring to WEATHER TYPE * Icon referred in * Description WIND DIRECTION * Icon referred in * Description located in having COUNTRY * Name o Geographical Position

about

FORECAST * Date o Minimum Temperature o Maximum Temperature o Wind Force

referring to

1-38

Copyright © Oracle Corporation, 2002. All rights reserved.

Graphical Elements of ER Diagram

Entity Attribute Relationship Subtype Unique identifier Arc Nontransferability
# o # * *
o

* *

1-39

Copyright © Oracle Corporation, 2002. All rights reserved.

Summary

• • • • •

ER Modeling models information conceptually Based on functional business needs “What”, not “How” Diagrams provide easy means of communication Detailed, but not too much

1-40

Copyright © Oracle Corporation, 2002. All rights reserved.

Practices

• • • • •

Instance or Entity Guest Reading Hotel Recipe

1-41

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Instance or Entity?
Concept
PRESIDENT ELLA FITZGERALD DOG ANIMAL HEIGHT E A I CAR CAR CAR

E/A/I? Example Instance or Entity

1-42

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Guest
Address Arrival Date GUEST HOTEL ROOM Family Name Room Number Floor Number Number of Beds Number of Parking Lots Price TV set available?

1-43

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Reading
EMPLOYEE
assigned to responsible for

DEPARTMENT

A

Each EMPLOYEE may be assigned to one or more DEPARTMENTS Each DEPARTMENT must be responsible for one or more EMPLOYEES

B

Each EMPLOYEE must be assigned to one or more DEPARTMENTS Each DEPARTMENT may be responsible for one or more EMPLOYEES

C

Each EMPLOYEE must be assigned to exactly one DEPARTMENT Each DEPARTMENT may be responsible for exactly one EMPLOYEE

1-44

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Read and Comment
PERSON born in birthplace of living in home town of visitor of visited by mayor of with mayor TOWN

1-45

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Hotel
HOTEL * Address the lodging for ROOM * Room Number with in in of with guest in PERSON * Name host of

STAY * Arrival Date

1-46

Copyright © Oracle Corporation, 2002. All rights reserved.

Ralph’s Raving Recipes Soups

Açorda alentejana
bread soup from Portugal
For 4 persons:

vegetarian 15 min easy

1 onion 4 cloves of garlic 1 red pepper 1 liter of vegetable broth 4 tablespoons of olive oil 4 fresh eggs 1 handful of parsley or coriander salt, pepper 9-12 slices of (old) bread Cut the onion into small pieces and fry together with the garlic. Wash the red pepper, cut it in half, remove the seeds and fry it for at least 15.
page 127

Preparation

1-47

Copyright © Oracle Corporation, 2002. All rights reserved.

1-48

Copyright © Oracle Corporation, 2002. All rights reserved.

Entities and Attributes in Detail

Copyright © Oracle Corporation, 2002. All rights reserved.

Overview

• • • •

Data compared to information Entities and how to track them down Attributes Subtypes and supertypes

1-2

Copyright © Oracle Corporation, 2002. All rights reserved.

Data Compared to Information

Data • Facts given from which other facts may be inferred • Raw material • Example: Telephone Directory Information • Knowledge, intelligence • Example: Telephone number of florist

1-3

Copyright © Oracle Corporation, 2002. All rights reserved.

Data

Modeling, Conceptual Structuring data concepts into logical, coherent, and mutually related groups Modeling, Physical Modeling the structure of the (future) physical database Base A set of data, usually in a variety of formats, such as paper and electronically-based Warehouse A huge set of organized information

1-4

Copyright © Oracle Corporation, 2002. All rights reserved.

Entities

• • • • • • •

Give the entity a unique name Create a formal description of the entity Add a few attributes, if possible Be aware of homonyms Check entity names and descriptions regularly Avoid use of reserved words Remove relationship name from entity name

1-6

Copyright © Oracle Corporation, 2002. All rights reserved.

Relationship Name in Entity Name

GUEST guest of host of

HOTEL

PERSON

guest of host of

ACCOMMODATION

1-8

Copyright © Oracle Corporation, 2002. All rights reserved.

Some Background Information

“ElectronicMail (EM) wants to provide an attractive and user- friendly Web-based e-mail system. Important concepts are user and message. An EM user has a unique address of 30 characters at most and a password supplied by the person who set up the EM user. Who the person really is, we do not know, although we ask for some additional information, such as the name, country, birth date, line of business, and a few more things.

1-9

Copyright © Oracle Corporation, 2002. All rights reserved.

Some Background Information

Users must be able to send and receive mail messages. A mail message is usually a piece of straight text. A message may have attached files. An attachment is a file, like a spreadsheet, that is sent and kept with the message, but not created with our software. Messages are kept in folders. Every user has three folders to start with: Inbox, Outbox, and Wastebasket. Additional folders can be created by the user.”

1-10

Copyright © Oracle Corporation, 2002. All rights reserved.

(0

ORJR
Folders

Compose
Addresses Preferences Get New Mail Exit

Compose
Subject: To: Cc: Bcc: Message text:
test myself

DGYHUWLVHPHQW DUHD s
Template
default bipi, giovanni_papini@yahoo.com

DGYHUWLVHPHQW DUHD

ke s

h oKeep tc Copy

sc f

en re

this is a test and a text as well tralalalala pompidom

oc t

os mp o

a il em

ss Send me

ge a

Save Draft Save Template Cancel

Attachments: Add Signature
abc.html xyz.doc

Type:
Hypertext Word document

1-11

Copyright © Oracle Corporation, 2002. All rights reserved.

(0

ORJR
Folders

DGYHUWLVHPHQW DUHD
Addresses
Nicknames Alias
apple bipi joe myself

Compose
Addresses Preferences Get New Mail Exit

Email address

DGYHUWLVHPHQW DUHD

e tc sk

cre friends fs bipi ho
Group

nt e

int ma o

w.j.appletree@cats.com sabine_papini @yahoo.com j.suspender@last.com jtiddlywink@em.com

na ai

es s es dr d

joe giovanni_papini@yahoo.com p.g.m.papini@em.com

1-12

Copyright © Oracle Corporation, 2002. All rights reserved.

Some Desired Functionality

“Users of ElectronicMail must be able to address messages to a mail list, for example, a group of email addresses. The system should only keep one copy of the message sent (to save database space) plus information about whom the message was sent to. Users must be able to create templates for their messages. A template must be named and may contain everything a real message contains. A template may be used for new messages.

1-13

Copyright © Oracle Corporation, 2002. All rights reserved.

Some Desired Functionality

Users must be able to reply to a message. By replying the user creates a new message to which the old message is added. Users must be able to create an alias for an e-mail address, to hide the often complex addresses behind an easy-to-remember nickname.”

1-14

Copyright © Oracle Corporation, 2002. All rights reserved.

Evolution of an Entity Definition

• • •

A message is a piece of text sent by a user. A message is a piece of text sent by an EM user. A message is a note that is sent by an EM user. A message does not necessarily contain text, nor a subject, etc. A message is a note that is sent by an EM user or received by an EM user or both. A message does not necessarily contain text, nor a subject, etc. A message is a note that is received by an EM user. A message does not necessarily contain text, nor a subject, etc.

1-15

Copyright © Oracle Corporation, 2002. All rights reserved.

Business Functions

“Users of ElectronicMail must be able to address messages to a mail list, for example, a group of email addresses. The system should only keep one copy of the message sent (to save data base space) plus information about whom the message was sent to. Users must be able to create templates for their messages. A template must be named and may contain everything a real message contains. A template may be used for new messages.

1-17

Copyright © Oracle Corporation, 2002. All rights reserved.

Business Functions

Users must be able to reply to a message. By replying the user creates a new message to which the old message is added. Users must be able to create an alias for an e-mail address, to hide the often complex addresses behind an easy-to-remember nickname.”

1-18

Copyright © Oracle Corporation, 2002. All rights reserved.

An Attribute...

• • • •

Always answers “of what?” Is the property of entity, not of relationship Must be single valued Has format, for example:
– – – – – Character string Number Date Picture Sound

Is an elementary piece of data

1-19

Copyright © Oracle Corporation, 2002. All rights reserved.

Nouns, Entities, Attributes

“ElectronicMail (EM) wants to provide an attractive and user friendly Web-based email system. Important concepts are user and message. An EM USER has a unique address of 30 characters at most and a password supplied by the PERSON who set up the EM user. Who the person really is, we do not know, although we ask for some additional information, like the name, COUNTRY, birth date, line of business, and a few things more.

1-20

Copyright © Oracle Corporation, 2002. All rights reserved.

Nouns, Entities, Attributes

Users must be able to send and receive mail MESSAGES. A mail message is usually a piece of straight text. A message may have attached files. An ATTACHMENT is a file, like a spreadsheet, that is sent and kept with the message, but not created with our software. Messages are kept in FOLDERS. Every user has three folders to start with: Inbox, Outbox and Wastebasket. Additional folders can be created by the user.”

1-21

Copyright © Oracle Corporation, 2002. All rights reserved.

EM Entities and Attributes
Nouns user address password person name country birth date occupation message text attachment file folder inbox outbox wastebasket
1-22

Entities/Attributes/ Instances USER Address Password PERSON Name COUNTRY Birth Date Occupation MESSAGE Text ATTACHMENT File FOLDER Inbox Outbox Wastebasket

Entities with their Attributes USER - Address - Password PERSON - Name - Birth Date - Occupation COUNTRY - Name MESSAGE - Text ATTACHMENT - Filename FOLDER - Name

Copyright © Oracle Corporation, 2002. All rights reserved.

Attribute and Entity
GARMENT Name Price

Attributes in one model can be entities in another.

GARMENT

CURRENCY

PRICE

NAME

LANGUAGE

1-23

Copyright © Oracle Corporation, 2002. All rights reserved.

Redundancy

COMMODITY * Name * Price exclusive VAT * Price inclusive VAT * VAT %

1-24

Copyright © Oracle Corporation, 2002. All rights reserved.

A Subtype ...

• • • • • • •

Inherits all attributes of supertype Inherits all relationships of supertype Usually has its own attributes or relationships or business functions Is drawn within supertype Never exists alone ADDRESS May have subtypes of its own USER Is also known as “Subentity”
LIST

1-25

Copyright © Oracle Corporation, 2002. All rights reserved.

Subtype: Example

COMPOSITION o Subject o Cc o Bcc o Text MESSAGE

DRAFT * Name TEMPLATE * Name

1-26

Copyright © Oracle Corporation, 2002. All rights reserved.

Subtype: Rules

Subtypes of the same entity must be: • Exhaustive: Every instance of a supertype is also instance of one of the subtypes. and • Mutually exclusive: Every instance of the supertype is of one and only one subtype. Name subtypes adequately:
A B C NON B OTHER A

1-27

Copyright © Oracle Corporation, 2002. All rights reserved.

Subtypes: Three Levels

COMPOSITION o Subject o Cc o Bcc o Text MESSAGE

OTHER COMPOSITION * Name DRAFT *DRAFT Name TEMPLATE TEMPLATE * Name

1-28

Copyright © Oracle Corporation, 2002. All rights reserved.

More on Subtypes

Subtypes always exist...
EMPLOYEE CURRENT EMPLOYEE OTHER EMPLOYEE

... but do not all make sense
EMPLOYEE EMPLOYEE WITH SHOE SIZE > 45 OTHER EMPLOYEE

1-29

Copyright © Oracle Corporation, 2002. All rights reserved.

Summary

Entities • Nouns in texts • Tangible, intangible, events Attributes • Single-valued qualifiers of entities Subtypes • Inherit all attributes and relationships of supertype • May have their own attributes and relationships

1-30

Copyright © Oracle Corporation, 2002. All rights reserved.

Practices

• • • • • •

Books Moonlight Coffees Shops Subtypes Schedule Address

1-31

Copyright © Oracle Corporation, 2002. All rights reserved.

1. I have just finished writing a book. It’s a novel about justice and power. 2. We have just published this book. The hard cover edition is available now. 3. Did you read that new book on Picasso? I did. It's great! 4. If you like you can borrow my book. 5. I have just started translating this book into Spanish. I use the modern English text as a basis and not the original, which is 16th century. 6. I ordered that book for my parents.

1-32

Copyright © Oracle Corporation, 2002. All rights reserved.

7. Yes, we have that book available. You should find it in Art books. 8. A second printing of the book War and Peace is very rare. 9. I think My name is Asher Lev is one of the best books ever written. Mine is autographed. 10. I want to write a book on entity relationship modeling when I retire.

1-33

Copyright © Oracle Corporation, 2002. All rights reserved.

Moonlight Coffees

Summary

Moonlight Coffees is a fast growing chain of high quality coffee shops with currently over 500 shops in 12 countries of the world. Shops are located at first-class locations, such as major shopping, entertainment and business areas, airports, railway stations, museums. Moonlight Coffees has some 9,000 employees. Products • All shops serve coffees, teas, soft drinks, and various kinds of pastries. Most shops sell nonfoods, like postcards and sometimes even theater tickets.

1-34

Copyright © Oracle Corporation, 2002. All rights reserved.

Moonlight Coffees

Summary

Financial Shop management reports sales figures on a daily basis to Headquarters, in local currency. Moonlight uses an internal exchange rates list that is changed monthly. Since January 1, 1999, the European Community countries must report in Euros. Stock Moonlight Coffees is a public company; stock is traded at NASDAQ, ticker symbol MLTC. Employees can participate in a stock option plan.

1-35

Copyright © Oracle Corporation, 2002. All rights reserved.

Moonlight Coffees

Shop List

Shoplist, ordered to date opened page 4 181 The Flight, JFK Airport terminal 2, New York, USA, 212.866.3410, Airport, 12-oct-97 182 Hara, Kita Shinagawa,Tokyo, JP, 3581.3603/4, Museum, 25-oct-97 183 Phillis, 25 Phillis Rd, Atlanta, USA, 405.867.3345, Shopping Centre, 1-nov-97 184 JFK, JFK Airport terminal 4, New York, USA, 212.866.3766, Airport, 1-nov-97

1-36

Copyright © Oracle Corporation, 2002. All rights reserved.

Moonlight Coffees

Shop List

185 VanGogh, Museumplein 24, Amsterdam, NL, 76.87.345, Museum, 10-nov-97 186 The Queen, 60 Victoria Street, London, UK, 203.75.756, Railway Station, 25-nov-97 187 Wright Bros, JFK Airport terminal 1, New York, USA, 212.866.9852, Airport, 6-jan-98 188 La Lune, 10 Mont Martre, Paris, FR, 445 145 20, Entertainment, 2-feb-98

1-37

Copyright © Oracle Corporation, 2002. All rights reserved.

Subtypes
DISABLED PERSON DEAF BLIND OTHER DISABLED PERSON HOTEL ROOM WITH BATH OTHER ROOM CAR STATION WAGON SEDAN

BUILDING

HOUSE

DOG DOMESTIC ANIMAL MAMMAL

1-38

Copyright © Oracle Corporation, 2002. All rights reserved.

van Gogh, Museumplein, Amsterdam Schedule Oct 12 - Oct 18 Shift Annet S Annet B Dennis Jürgen Kiri Wil 3 4 1 2 2 1 2 Mon Tue Wed 2 prepared by Janet Thu Fri 2 1 3 5 4 4 Sat 2 1 Sun 1

1-39

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Address (1/2)

Rheingasse 123 53111 Bonn Germany 1020 Maple Drive Kirkland WA 98234 USA

34 Oxford Road Reading Berkshire RG1 8JS UK

1-40

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Address (2/2)

P.O. Box 66708 Nairobi Kenya

c/o Mrs Smith Maude Street Sandton Johannesburg 2144 South Africa

1-41

Copyright © Oracle Corporation, 2002. All rights reserved.

Relationships in Detail

Copyright © Oracle Corporation, 2002. All rights reserved.

Overview

• • • • •

Relationships Ten different relationship types Nontransferability Relationships that seem to have attributes Rules of Normalization

3-2

Copyright © Oracle Corporation, 2002. All rights reserved.

Establishing a Relationship

• • • • •

Determine the existence of a relationship Choose a name for the relationship from both perspectives Determine optionality Determine degree Determine nontransferability

3-3

Copyright © Oracle Corporation, 2002. All rights reserved.

Establishing the Relationship

MESSAGE

sending receiving

USER

replying

3-4

Copyright © Oracle Corporation, 2002. All rights reserved.

Relationship Names

MESSAGE

sent by sent to reply of

sender USER of

receiver of

replied to by

3-5

Copyright © Oracle Corporation, 2002. All rights reserved.

Naming the Relationship

receiving MESSAGE received by receiver of USER

A MESSAGE is received by a USER A USER is receiver of a MESSAGE

3-6

Copyright © Oracle Corporation, 2002. All rights reserved.

Optionality

MESSAGE

written by received by reply of

author USER of

receiver of

replied to by

3-7

Copyright © Oracle Corporation, 2002. All rights reserved.

Optionality
No: Yes:

MESSAGE

received by receiver of

USER

• •

Must every MESSAGE be received by a USER? Yes Must every USER be receiver of a MESSAGE? No

3-8

Copyright © Oracle Corporation, 2002. All rights reserved.

Mandatory 1: Mandatory m

A

split into part of

B

• •

Every A must be split into at least one B Every B must be part of exactly one A

3-9

Copyright © Oracle Corporation, 2002. All rights reserved.

Degree

MESSAGE

written by received by reply of

author USER of

receiver of

containing with <5

replied to by

ATTACHMENT

3-10

Copyright © Oracle Corporation, 2002. All rights reserved.

Degree
One: One or more:

MESSAGE

received by receiver of

USER

• •

Can a MESSAGE be received by more Yes than one USER? Can a USER be the receiver of more than one Yes MESSAGE ?

3-11

Copyright © Oracle Corporation, 2002. All rights reserved.

Nontransferability
FOLDER containing filed in MESSAGE written by received by reply of replied to by receiver of author USER of

3-12

Copyright © Oracle Corporation, 2002. All rights reserved.

Relationship Types 1:m

(a) (b) (c) (d)

3-13

Copyright © Oracle Corporation, 2002. All rights reserved.

Relationship Types m:1

PRODUCT part of consists of BUNDLE

3-15

Copyright © Oracle Corporation, 2002. All rights reserved.

Relationship Types m:m

(e) (f) (g)

3-16

Copyright © Oracle Corporation, 2002. All rights reserved.

Relationship Types m:m

USER part of consists of

LIST

3-17

Copyright © Oracle Corporation, 2002. All rights reserved.

Relationship Types 1:1

(h) ( i) (j)

3-18

Copyright © Oracle Corporation, 2002. All rights reserved.

1:1 Relationships Roles

PERSON * Name

acting as role of acting as role of

PATIENT * Blood Type

EMPLOYEE * Job

3-19

Copyright © Oracle Corporation, 2002. All rights reserved.

1:1 Relationships Process

MESSAGE DRAFT basis for result of

3-20

Copyright © Oracle Corporation, 2002. All rights reserved.

Redundant Relationships

COUNTRY location of of

COUNTRY location of located in TOWN hometown of living in PERSON of birth of

located in TOWN

hometown of living in PERSON

living in

born in

3-21

Copyright © Oracle Corporation, 2002. All rights reserved.

Relationships and Attributes

• •

An attribute can hide a relationship Relationship can be “downgraded” to attribute

ATTACHMENT TYPE * Name of with ATTACHMENT * Type * Content ATTACHMENT * Content

3-22

Copyright © Oracle Corporation, 2002. All rights reserved.

Attribute Compared to Relationship

• • •

Easy model Fewer tables No join

• • •

Value control List of values Other relationships

ATTACHMENT TYPE * Name of with ATTACHMENT * Type * Content ATTACHMENT * Content

3-23

Copyright © Oracle Corporation, 2002. All rights reserved.

Attribute or Entity

NAME SALARY GENDER TEAM

EMPLOYEE * Id

JOB BADGE NATIONALITY ADDRESS

3-24

Copyright © Oracle Corporation, 2002. All rights reserved.

Attribute Compared to Relationship

• •

There is no such thing as a foreign key attribute Usually, the attribute name should not contain an entity name FOLDER
* Name containing placed in MESSAGE * Message Id * Text * Folder Name

3-25

Copyright © Oracle Corporation, 2002. All rights reserved.

Relationship Compared to Attribute

MESSAGE

addressed to addressee of

USER

MESSAGE * Addressee

USER

MESSAGE o Addressee

addressed to addressee of

USER

3-26

Copyright © Oracle Corporation, 2002. All rights reserved.

m:m Relationships May Hide Something

CUSTOMER * Id * Name

buyer of bought by

PRODUCT * Code * Name

3-27

Copyright © Oracle Corporation, 2002. All rights reserved.

Quantity Is Attribute of ...
? CUSTOMER * Id * Name Quantity buyer of bought by * Code * Name PRODUCT

? CUSTOMER * Id * Name buyer of bought by * Code * Name Quantity PRODUCT

3-28

Copyright © Oracle Corporation, 2002. All rights reserved.

Attribute of Relationship ?

CUSTOMER * Id * Name buyer of bought by Quantity

PRODUCT * Code * Name

3-29

Copyright © Oracle Corporation, 2002. All rights reserved.

New Entity ORDER
CUSTOMER * Id * Name PRODUCT * Code * Name CUSTOMERS Id Name 1 Sanchez 2 Lowitch 3 Yomita 4

with of with for ORDER *Quantity Sold

PRODUCTS Code Name 1 Jeans 2 Shirt 3 Tie 4

ORDERS Ctr_id Pdt_code Quantity_sold 1 1 2 3 2 3 2 2 2 1

3-30

Copyright © Oracle Corporation, 2002. All rights reserved.

Multiple PRODUCTS for an ORDER

CUSTOMER * Id * Name PRODUCT * Code * Name

with of with for
Qu an t ity ?

ORDER * Id * Date

3-31

Copyright © Oracle Corporation, 2002. All rights reserved.

Another New Entity: ORDER ITEM
CUSTOMER * Id * Name PRODUCT * Code * Name

with of

ORDER HEADER * Id * Date

with with for ORDER ITEM *Quantity Sold for

3-32

Copyright © Oracle Corporation, 2002. All rights reserved.

Tables
CUSTOMERS Id Name ORDER_HEADERS Id Ctr_id 1 2 1 2 Date_ordered 25-MAY-1999 25-MAY-1999 25-MAY-1999 1 Sanchez Lowitch 2 Yomita

ORDER_ITEMS Ohd_id 1 2 Pdt_code Quantity_sold 2 2 2 2 1

PRODUCTS Code Name 1 Jeans 2 Shirt 3 Tie 4

3-33

Copyright © Oracle Corporation, 2002. All rights reserved.

Resolving m:m Relationship

• • •

Create new intersection entity Create two m:1 relationships, derive optionality Remove m:m relationship
A A in of xxx yyy B B in of A/B COMBINATION

3-34

Copyright © Oracle Corporation, 2002. All rights reserved.

Resolving m:m Relationship
• • • Create new intersection entity Create two m:1 relationships, derive optionality Remove m:m relationship
A with of xxx yyy B with of A/B COMBINATION

3-36

Copyright © Oracle Corporation, 2002. All rights reserved.

Resolving m:1 Relationship

external PERSON classified as CUSTOMER classification TYPE of

internal

3-37

Copyright © Oracle Corporation, 2002. All rights reserved.

Resolving m:1 Relationship

external PERSON CUSTOMER TYPE with for CLASSIFICATION internal in with

3-38

Copyright © Oracle Corporation, 2002. All rights reserved.

Normalization Rules
Normal Form Rule First Normal Form Second Normal Form (2NF) Description All attributes are single valued. An attribute must be dependent upon entity’s entire unique identifier. No non-UID attribute can be dependent on another non-UID attribute.

Third Normal Form (3NF)

“A normalized entity-relationship data model automatically translates into a normalized relational database design” “Third normal form is the generally accepted goal for a database design that eliminated redundancy”

3-39

Copyright © Oracle Corporation, 2002. All rights reserved.

First Normal Form in Data Modeling
USER # Name * Person Name * Message Receive Date o Message Subject o MessageText All attributes must be single-valued. RECEIVED MESSAGE # Receive Date o Subject o Text received by receiver of USER # Name * Person Name

3-40

Copyright © Oracle Corporation, 2002. All rights reserved.

Second Normal Form in Data Modeling
An attribute must be dependent upon its entity’s entire unique identifier.
RECEIVED MESSAGE # User Name * Receive Date * Subject RECEIVED MESSAGE # User Name * Receive Date MESSAGE # Id o Text

including included in

including

MESSAGE # Id included o Text in * Subject

3-41

Copyright © Oracle Corporation, 2002. All rights reserved.

Third Normal Form in Data Modeling
USER # Name * Person Name * Password * Server Id * Server Name

No non-UID attribute can be dependent upon another non-UID attribute.
USER # Name * Person Name * Password assigned to MAIL SERVER # Id distribut * Name e mail to

3-42

Copyright © Oracle Corporation, 2002. All rights reserved.

Summary

• • • •

Relationships express how entities are connected. Initially relationships often seem to be of type m:m. Finally relationships are most often of type m:1. Relationships can be resolved into:
– Two new relationships – One intersection entity

Third Normal form is generally accepted standard.

3-43

Copyright © Oracle Corporation, 2002. All rights reserved.

Practices

• • • • • • • •

Read the Relationship Find a Context Name the Intersection Entity Receipt Moonlight P&O Price List EMail Holiday

3-44

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Read the Relationship
ALU of with BRY

PUR

bazooned in bazooned by

YOK

KLO

bilought in glazoed with

HAR

3-45

Copyright © Oracle Corporation, 2002. All rights reserved.

Find a Context (1)

3-46

Copyright © Oracle Corporation, 2002. All rights reserved.

Find a Context (2)

3-47

Copyright © Oracle Corporation, 2002. All rights reserved.

Find a Context (3)

3-48

Copyright © Oracle Corporation, 2002. All rights reserved.

Find a Context (4)

3-49

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Name the Intersection Entity

PRODUCT

sold by selling

DEPARTMENT STORE

PERSON

crewing crewed by

SAILBOAT

INTERPRETER

fluent in spoken by

LANGUAGE

3-50

Copyright © Oracle Corporation, 2002. All rights reserved.

Served by: Dennis Till: 3 Dec 8, 4:35 pm ----------------------CAPPUCC M 3.60 * 2 7.20 CREAM .75 * 2 1.50 APPLE PIE 3.50 BLACKB MUF 4.50 <SUB> 16.70 tax 12% 2.00 <TOTAL> 18.70 ======= CASH 20.00 RETURN 1.30 ----------------------Hope to serve you again @MOONLIGHT COFFEES 25 Phillis Rd, Atlanta

Practice: Receipt

3-51

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Moonlight P&O
• All Moonlight Coffee employees work for a department such as “Global Pricing” or “HQ”, or for a shop. All employees are at the payroll of one of our country organizations. Jill, for example, works as a shop manager in London; Werner is a financial administrator working for Accounting and is located in Germany. All shops belong to one country organization (“the countries”). There is only one country organization per country. All countries and departments report to HQ, except HQ itself. Employees can work part time. Lynn has had an 80% assignment for Product Development since the 1st September. Before that she had a full-time position.

3-52

Copyright © Oracle Corporation, 2002. All rights reserved.

price list

Practice: Price List
small medium large
3.50 4.20 3.90 4.40 3.50 3.00 .75 3.50 3.90 4.20 3.00 .75 2.50 3.50 3.50 4.20 3.50

25 Phillis Road, Atlanta visit us at www.moonlight.com

regular coffee 2.25 2.90 cappuccino 2.90 3.60 café latte 2.60 3.20 special coffee 3.10 3.70 espresso 2.25 2.90 coffee of the day 2.00 2.50 decaffeinated .25 .50 black tea 2.25 2.90 infusions 2.60 3.20 herbal teas 2.90 3.60 tea of the day 2.00 2.50 decaffeinated .25 .50 milk 1.25 1.90 soft drinks 2.25 2.90 soda water 2.25 2.90 mineral water 2.90 3.60 apple pie strawberry cheesecake whole wheat oats muffin with almonds blackberry muffin fruitcake cake of the day additional whipped cream

extra

extra

Sales Tax included September 16

3.50 3.90 4.50 4.50 4.00 .75

3-54

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: E-Mail
FOLDER containing placed in COMPOSITION MESSAGE written by received by receiver of reply of author of USER part of consist s of

LIST

OTHER COMPOSITION containing replied to by

with <5 ATTACHMENT

ATT. TYPE

3-55

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Holiday
“Paul and I hiked in the USA. Eric and I hiked in France and we rented a car in the USA last year.” COUNTRY France USA USA
CO Fr U US an NT US A ce RY A

TRANSPORT Boots Boots Car TRANSPORT
TR Bo AN Ca ot SP O Bo r s RT ot s

COUNTRY

3-56

Copyright © Oracle Corporation, 2002. All rights reserved.

CO Er M E r ic P A NI P a ic O N ul

CO Er M COMPANION Er ic PA NI Pa ic O ul N

Practice: Normalize an ER Model
ENROLLMENT grade code teacher number grade description course name for assigned STUDENT #* student id last name first name for completed with COURSE course number course name teacher number department code department name teacher name

3-57

Copyright © Oracle Corporation, 2002. All rights reserved.

Constraints

Copyright © Oracle Corporation, 2002. All rights reserved.

Overview

• • • •

Unique Identifiers Arcs Domains Various other constraints

4-2

Copyright © Oracle Corporation, 2002. All rights reserved.

Rembrandt

4-3

Copyright © Oracle Corporation, 2002. All rights reserved.

4-4

Copyright © Oracle Corporation, 2002. All rights reserved.

Identification and Representation
G. Papini, please? EMPLOYEES Name Initials PAPINI HIDE PAPINI BAKER G. T.M. G. S.J.T.

Birthdate 02-FEB-1954 11-JUN-1961 02-FEB-1945 24-SEP-1958

4-5

Copyright © Oracle Corporation, 2002. All rights reserved.

Unique Identifier Examples
JOB Name COMPUTER IN NETWORK IP Address TELEPHONE Country code, Area code, Telephone number EMPLOYEE Employee number or Name, Initials, Birth Date MAIL LIST Name, Owner

4-6

Copyright © Oracle Corporation, 2002. All rights reserved.

Unique Identifier

Indicates Unique Identifier ORDER # Date by responsible for

CUSTOMER # Family Name o Initials # Address o Telephone

Indicates Unique Identifier

4-7

Copyright © Oracle Corporation, 2002. All rights reserved.

Unique Identifiers
USER # Name part of contains owner of owned by MAIL LIST # Name

ROOM # No

FLOOR # No

HOTEL # Name

4-8

Copyright © Oracle Corporation, 2002. All rights reserved.

Multiple Relationship UID
USER # Name part of contains LIST # Name owner of owned by USER # Name is referred to owner of owned by LIST # Name contains referring to LIST ITEM contained in

4-10

Copyright © Oracle Corporation, 2002. All rights reserved.

Well-defined Unique Identifiers
Z # Z1 o Z2 o Z3 # Z4 Q # Q1 Y # Y1 # Y2 P # P1

K L # L1 M # M1

X # X1

XY

R # R1

T # T1

S

4-12

Copyright © Oracle Corporation, 2002. All rights reserved.

Incorrect Unique Identifiers
K # K1 L # L1 F # F1 G # G1

P # P1 KL

R # R1

T o # T1

Q # Q1 H

G # G1

4-13

Copyright © Oracle Corporation, 2002. All rights reserved.

Information-Bearing Codes
54.0.093.81
Product Group In Production? Factory Sequence Number

PRODUCT # Code * In Production? * Sequence No

PRODUCT GROUP # Code FACTORY # Id

4-14

Copyright © Oracle Corporation, 2002. All rights reserved.

Arcs
Contract

Conditions 1 2 3 4 5 6

Std?

“A contract consists of contract components; these are standard conditions or customized conditions”

CONTRACT

STANDARD basis for CONDITION based consists in on of CUSTOMIZED CONDITION Arc in

Indicates relationship in arc

part of referring to referring to CONTRACT COMPONENT

4-15

Copyright © Oracle Corporation, 2002. All rights reserved.

Exclusive Arc

USER

owner of owned by LIST

is referred to container of contained referring to in LIST ITEM

is referred to

referring to

4-16

Copyright © Oracle Corporation, 2002. All rights reserved.

Possible Arc Constructs

4-17

Copyright © Oracle Corporation, 2002. All rights reserved.

Some Incorrect Arc Constructs

• • •

The arc “belongs” to one entity Relationships in the arc must be of the same optionality Arcs must contain at least two relationships

An arc may be correct, but is quite difficult to implement ...
4-18 Copyright © Oracle Corporation, 2002. All rights reserved.

Some Incorrect Arc Constructs
Number of Valid Relationships in Arc Per Entity Instance }n Minimum n Maximum n

}n

1

1

}n

0

n

}n

0

1

4-19

Copyright © Oracle Corporation, 2002. All rights reserved.

Arc or Subtype

USER owner of owned by LIST is referred to contains referring to in LIST ITEM is referred to referring to

ADDRESS USER owner of owned by LIST contains is referred to in referring to LIST ITEM

4-20

Copyright © Oracle Corporation, 2002. All rights reserved.

Arc and Subtypes
A 1 2 A

R P

Q

P

Q A C

A A B 3 4 R P Q P C B

C 5 Q

B

R P

Q

4-21

Copyright © Oracle Corporation, 2002. All rights reserved.

Subtypes Hide Relationships in Arc

• • •

Every A is either a B or a C Every B is an A Every C is an A
A B C

• • •

Every A must be a B or be a C Every B must be an A Every C must be an A
A
is B is is is

C

4-22

Copyright © Oracle Corporation, 2002. All rights reserved.

Value sets
CODE TYPE # Id * Name * Max Length of Description

YESNO # Code * Description

A B GENDER # Code * Description

WEEKDAY # Code * Description

CODE # Code * Description

4-23

Copyright © Oracle Corporation, 2002. All rights reserved.

Other Constraints: Range Check

EMPLOYEE * Name * Address with for

JOB * Title * Minimum Salary * Maximum Salary of referring to

between

EMPLOYMENT * Start Date o End Date * Salary

4-24

Copyright © Oracle Corporation, 2002. All rights reserved.

Other Constraints: State Value Transition

EMPLOYEE * Name * Address * Current Marital Status

Possible to Marital Status Transitions fro m Single Married Widowed Divorced Domestic Partnership

4-25

Copyright © Oracle Corporation, 2002. All rights reserved.

Sin Mar Wid Div DP

Conditional Relationship
CONTRACT # Id * Standard Indicator consists of

STANDARD basis for CONDITION based on in CUSTOMIZED CONDITION in

part of referring to CONTRACT COMPONENT referring to

4-26

Copyright © Oracle Corporation, 2002. All rights reserved.

Boundaries
EXTERNAL # Id * Description * Value

unrelated entity

and possible implementation EXTERNALS Id Description 1 2 3 4 Value added tax % Maximum available Space per Mail User in Mbyte Maximum level of Nested Mail Folders Maximum level of Nested Mail Lists Value 15 500 3 16

4-28

Copyright © Oracle Corporation, 2002. All rights reserved.

Summary

Identification
– Can be a real problem in the real world – Models cannot overcome this

• • • •

Entities must have at least one Unique Identifier Unique Identifiers consist of attributes or relationships or both Arcs Many types of constraint are not represented in ER model

4-29

Copyright © Oracle Corporation, 2002. All rights reserved.

Practices

• • • • •

Identification Please Identification Moonlight UID Tables Modeling Constraints

4-30

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Identification Please

• • • • • • • •

A city A contact person for a customer A train A road A financial transaction An Academy Award (Oscar) A painting A T.V. show

4-31

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Identification 1

A # Xx

B * Yy

C # Zz

4-32

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Identification 2

A C # Code

B # Id

4-33

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Identification 3

A * Xx B # Yy

C # Zz

with of

D # Id

4-34

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Identification 4

P

Q # Id

4-35

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Identification 5

P # Name

4-36

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Identification 6
PERSON MALE # Seqno son of FEMALE # Name mother of # Birth Date partner in

partner in

with husband MARRIAGE # Start Date

with wife

4-37

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Moonlight UID
reporting to DEPARTMENT OTHER DEPARTMENT with with EMPLOYEE with of for for PAYROLL ENTRY SHOP with to as in
4-38 Copyright © Oracle Corporation, 2002. All rights reserved.

report of HQ report of

reporting to COUNTRY in ORGANIZATION with belongs to

COUNTRY of with in

for ASSIGNMENT

to

JOB

Practice: Table 1

“In a relational database system, data is stored in tables. Tables of a database user must have a unique name. A table must have at least one column. A column has a unique name within the table. A column must have a data type and may be Not Null. Tables can have one primary key and any number of unique keys. A key contains one or more columns of the table. A column can be part of more than one key.

4-39

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Table 1

A table can have foreign keys. A foreign key always connects one table with another. A foreign key consists of one or more columns of the one table that refers to key columns of the other table. “The sequence of columns within the key and foreign key is important.”

4-40

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Table 2
from to with referenced in with with

FOREIGN KEY # Name

TABLE # Name

with of

KEY # Name PRIMARY UNIQUE with

for ASSOCIATION # Seqno

from

to

in in COLUMN # Name in * Data Type o Not Null

in

for USAGE of # Seqno

4-41

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Constraints 1

EMPLOYEE # Name

managed by

manager of

4-42

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Constraints 2

USER # Name

owned by LIST owner of # Name owned by NICKNAME owner of # Alias

4-43

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Constraints 3

with subfolder FOLDER Name within owner of owned by

USER # Name

4-44

Copyright © Oracle Corporation, 2002. All rights reserved.

Modeling Change

Copyright © Oracle Corporation, 2002. All rights reserved.

Overview

• • • •

Date and time Modeling change over time Prices change Journaling

5-2

Copyright © Oracle Corporation, 2002. All rights reserved.

Change and Time

• • • • • • •

Every update means loss of information. Time in your model makes the model more complex. There are often complex join conditions. Users can work in advance. When do you model date/time as an entity? What constraints do arise? How do you handle journaling?

5-3

Copyright © Oracle Corporation, 2002. All rights reserved.

Entity DAY
DAY # Date * Public Holiday Indicator first day of starts on TASK ASSIGNMENT for * Duration in Hours of with TASK in # Id EMPLOYEE # Name

5-4

Copyright © Oracle Corporation, 2002. All rights reserved.

Modeling Change

EMPLOYEE # Id of

COUNTRY # Name in

for ASSIGNMENT # Start Date o End Date

as

5-6

Copyright © Oracle Corporation, 2002. All rights reserved.

Even a Country Has a Life Cycle

EMPLOYEE # Id of

COUNTRY # Name # Start Date * End Date in life cycle attributes

for ASSIGNMENT # Start Date o End Date

as

5-8

Copyright © Oracle Corporation, 2002. All rights reserved.

Products and Prices

PRODUCT # Id * Name with of PRICE * Price in $ # Start date o End Date PRICE = PRICED PRODUCT= HISTORICAL PRICE

5-10

Copyright © Oracle Corporation, 2002. All rights reserved.

What Price to Pay?

en

PRODUCT # Id * Name with of PRICE * Price in $ # Start date o End Date

referred by
be tw e

ORDER HEADER # Id * Order Date with of ORDER ITEM * Quantity Ordered referring to

5-11

Copyright © Oracle Corporation, 2002. All rights reserved.

Price List Search
between PRICE LIST # Id * Start Date o End Date with on PRICED PRODUCT * Price in $ of ORDER HEADER # Id * Order Date referred by with

PRODUCT # Id * Name with

of ORDER ITEM * Quantity referring Ordered to

5-12

Copyright © Oracle Corporation, 2002. All rights reserved.

Order for Priced Products

PRICE LIST # Id * Start Date o End Date with on PRICED PRODUCT * Price in $

PRODUCT # Id * Name with of

ORDER HEADER # Id * Order Date with

of referred by ORDER ITEM * Quantity Ordered referring to

5-13

Copyright © Oracle Corporation, 2002. All rights reserved.

Negotiated Prices

PRICE LIST # Id * Start Date o End Date with on PRICED PRODUCT * Price in $

PRODUCT # Id * Name with of

ORDER HEADER # Id * Order Date referred by with

of ORDER ITEM * Quantity Ordered referring * Negotiated Price to

5-14

Copyright © Oracle Corporation, 2002. All rights reserved.

Current Prices
PRODUCT # Id * Name * Current Price with old of PRICE * Price in $ # Start Date * End Date PRODUCT # Id * Name * Current Price with of PRICE * Price in $ # Start date o End Date o Current Indicator PRODUCT # Id * Name with

of PRICE * Price in $ # Start Date o End Date

5-16

Copyright © Oracle Corporation, 2002. All rights reserved.

Journaling
by by PAYMENT *Date Paid *Amount in $ to PAYMENT o Date Paid * Amount in $ with of AMOUNT MODIFICATION * Old Amount in $ * Modified by * Date Modification to

5-17

Copyright © Oracle Corporation, 2002. All rights reserved.

Summary

• •

Consider the need for keeping old values Time in your model is complicated:
– Implicit versions – References

Journaling

5-19

Copyright © Oracle Corporation, 2002. All rights reserved.

Practices

• • • •

Shift Strawberry Wafer Bundles Product Structure

5-20

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Shift
Museumplein, Amsterdam, March 21 Shift Mon Tue Wed Thu Fri 1 2 3 4 5
-

6:30 11:30 16:00 20:30 11:30 16:00 20:30 23:00 7:00 11:30 16:00 20:30 11:30 16:00 20:30 23:00 7:00 11:30 16:00 20:30 11:30 16:00 20:30 23:00 7:00 11:30 16:00 20:30 11:30 16:00 20:30 23:00 7:00 11:30 16:00 20:30 11:30 16:00 20:30 24:00

Sat/Sun 11:30 15:00 18:00 21:00 24:00

8:00 11:30 15:00 18:00 21:00

5-21

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Strawberry Wafer

Prices are at the same level within a country; prices are determined by the Global Pricing Department. Usually the prices for regular, global products are re-established once a year. Prices and availability for local specialties are determined by the individual shops. For example, the famous Norwegian Vafler med Jordbær (a delicious wafer with fresh strawberries) is only available in summer. Its price depends on the current local market price of fresh strawberries.

5-22

Copyright © Oracle Corporation, 2002. All rights reserved.

prijslijst
Practice: Price list

de Keyzer, Keyzerlei 15, Antwerpen bezoekt ons op ‘t Web: www.moonlight.com klein 60 90 75 99 60 45 5 60 75 80 50 5 60 60 75 middel 90 110 100 125 95 75 10 100 110 120 85 10 100 100 120 groot 120 140 130 150 110 100 15 120 130 140 100 15 130 130 140

gewone koffie cappuccino koffie verkeerd speciale koffies espresso koffie van de dag caffeine vrij zwarte thees vruchten thees kruiden thees dag thee caffeine vrij frisdranken diverse sodas mineraal water appel taart brusselse wafel portie chocolade bonbons koekje van eigen deeg portie slagroom

toeslag

toeslag

180 150 150 120 30

5-23

inclusief BTW 16 September

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Bundles(1)
A SweetTreat(tm) consists of a large soft drink plus cake of the day. A BigBox(tm) consist of a large coffee of the day plus two cakes of the day. A SuperSweetTreat(tm) consists of a SweetTreat(tm) plus whipped cream (on the cake). A FamilyFeast(tm) consists of two BigBoxes(tm) plus two SweetTreats™ plus a small surprise. A DecafPunch(tm) consists of a regular decaffeinated coffee or a regular decaffeinated tea, plus a blackberry muffin.

5-24

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Bundles(2)
PRODUCT GROUP # Name classification for

classified as

PRODUCT # Id * Name

5-25

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Product Structure

+ Products + Drinks + Coffees Regular Cappuccino Café Latte + Special Coffee Teas + Black Chinese Indian English + Infusions + Herbal Soft drinks Juices Orange Grape + Waters + Sodas + Dairy Products +Foods + Pastry + Candy Bars + Local Specialties +Non Foods Merchandise CDs + Stationary Other + Tickets + Art

5-26

Copyright © Oracle Corporation, 2002. All rights reserved.

Advanced Modeling Topics

Copyright © Oracle Corporation, 2002. All rights reserved.

Overview

• • •

Patterns Drawing conventions Generic modeling

6-2

Copyright © Oracle Corporation, 2002. All rights reserved.

Patterns
• • Similar structure Similar rules and constraints?

6-3

Copyright © Oracle Corporation, 2002. All rights reserved.

Patterns: Master–Detail

• •

Characteristic: consists of An instance of B only exists in the context of an A Metaphor: Master – Detail
A

consists of part of B

6-5

Copyright © Oracle Corporation, 2002. All rights reserved.

Pattern: Basket
A X Y Z

• • •

Characteristic: container for various types of items Items may be of different types Metaphor: Shopping Basket
A X consists of part of B Z

B

Y

6-6

Copyright © Oracle Corporation, 2002. All rights reserved.

Patterns: Hierarchy
• • • Characteristic: manager of / subordinate of Additional constraints to guard hierarchical nature Metaphor: Mother–Child

A # Id

6-8

Copyright © Oracle Corporation, 2002. All rights reserved.

Patterns: Chain

• • •

Characteristic: preceded by / followed by Sequence is important Metaphor: Elephants
preceded by BEAD # Id followed by A CHAIN B

BEAD # Seqno

6-10

Copyright © Oracle Corporation, 2002. All rights reserved.

Patterns: Network
• Characteristic: pairs Every A can be connected to every A (sometimes: to every other A) Metaphor: Web Document with Hyperlinks
A A A

6-11

Copyright © Oracle Corporation, 2002. All rights reserved.

6-12

Copyright © Oracle Corporation, 2002. All rights reserved.

Bill of Material
product of with part in in

PRODUCT # Code

COMPOSITION * Quantity Needed

PRODUCTS Code 914.53 914.54 914.55 914.56 Name AAAAAAAA AAA BBBBBBBB B CCCCCCC DDDDD

COMPOSITIONS Prod_code 854.01 854.01 854.01 914.54 914.54 934.76 Part_code Quantity 604.18 1 604.19 1 914.54 2 914.55 1 914.56 1 915.12 3

6-13

Copyright © Oracle Corporation, 2002. All rights reserved.

Bill of Material - Example
854.01

914.54

914.54

604.18

914.55 914.56

604.19

6-14

Copyright © Oracle Corporation, 2002. All rights reserved.

Symmetric Relationship

GROUP # Id consists of 2 in S

Group_id 1 1 2 2 3 3

S S1 S2 S3 S4 S5 S6

6-15

Copyright © Oracle Corporation, 2002. All rights reserved.

Patterns: Roles

• •

Characteristic: is / is 1:m (or 1:1) relationships Metaphor: Person–Many Hats (not necessarily concurrent...)
P

A

Q

6-16

Copyright © Oracle Corporation, 2002. All rights reserved.

Roles
PERSON ROLE TYPE roles ROLE

PERSON

PRESIDENT appointing appointed by MINISTER PARTY LEADER

COUNTRY

DEPARTMENT PARTY

6-17

Copyright © Oracle Corporation, 2002. All rights reserved.

Fan Trap

• •

Characteristic: ring of m:m related entities Metaphor: ABC Combination

A C

B A AB AC C BC B

6-18

Copyright © Oracle Corporation, 2002. All rights reserved.

Fan Trap Resolved

A

B

C

A

B

C

A

B

C

AB

BC

ABC AB functions as list of values

ABC

ABC BC functions as list of values

6-19

Copyright © Oracle Corporation, 2002. All rights reserved.

Patterns: Data Warehouse

• • •

Characteristic: multidimensional, many, many detail instances Metaphor: star model Stars may be strangely shaped: Snowflake model
July

B

C

A

X

D

F

E

6-20

Copyright © Oracle Corporation, 2002. All rights reserved.

Drawing Conventions

high volumes

high volumes

Not important which convention you choose, as long as you follow one of them

6-21

Copyright © Oracle Corporation, 2002. All rights reserved.

Use Conventions Sensibly

But: Readability first

6-22

Copyright © Oracle Corporation, 2002. All rights reserved.

Model Readability
B A C A B

E D F D

C

E

• •

Takes space Subject to taste
F

6-23

Copyright © Oracle Corporation, 2002. All rights reserved.

Generic Modeling
MANUFACTURER * Name MANUFACTURER * Name ARTICLE TYPE

FILM * AsaTRIPOD * Height LENS CAMERA * Focal BODY Distance * Weight

ARTICLE o Weight o Focal Distance o Height o Asa Number o ...

6-24

Copyright © Oracle Corporation, 2002. All rights reserved.

Generic Modeling

ARTICLE TYPE * Definition Prop1 o Definition Prop2 o Definition Prop3 o Definition Prop4 ...

MANUFACTURER * Name

ARTICLE o Property1 o Property2 o Property3 o Property4 o Property5 o Property6 o Property7 o Property8

6-25

Copyright © Oracle Corporation, 2002. All rights reserved.

Generic Model
ARTICLE TYPE

ARTICLE

PROPERTY

ARTICLE PROPERTY VALUE o Value

6-26

Copyright © Oracle Corporation, 2002. All rights reserved.

Generic

having some kind of relationship with THING having some kind of relationship with

6-27

Copyright © Oracle Corporation, 2002. All rights reserved.

More Generic

THING ASSOCIATION

6-28

Copyright © Oracle Corporation, 2002. All rights reserved.

More Generic Plus

THING TYPE

ASSOCIATION TYPE

THING ASSOCIATION

6-29

Copyright © Oracle Corporation, 2002. All rights reserved.

Most Generic?
THING TYPE ASSOCIATION TYPE

THING ASSOCIATION PROPERTY

THING PROPERTY VALUE

6-30

Copyright © Oracle Corporation, 2002. All rights reserved.

Best of Two Worlds

‘generic’ CUSTOMER ARTICLE TYPE ORDER HEADER ARTICLE ORDER ITEM ‘down to earth’ ARTICLE PROPERTY VALUE PROPERTY

6-31

Copyright © Oracle Corporation, 2002. All rights reserved.

Summary

Patterns • Show similarities • Invent your wheel only once Generic models • Reduce the number of entities dramatically • Are more complex to implement • Are very flexible • Are usually the best choice in unstable situations

6-32

Copyright © Oracle Corporation, 2002. All rights reserved.

Practices

• • • •

Patterns Data Warehouse Argos and Erats Synonym

6-33

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Patterns

• • • • • •

Model of moves in a chess game Model of tenders (quotations) Model of recipes Model of all people involved in college: students, teachers, parents, … Rentals in a video shop Model of phases in a process

6-34

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Data Warehouse

What is the sales volume in $ of coffee last month compared with the coffee sales volume same month last year? What is the sales volume in $ of coffee per head in Japan compared with the average coffee sales volume in the Moonlight countries around the world? What is the growth of the sales volume in $ of coffee in Sweden compared with the growth of sales volume of all products in the same geographical area? What is the growth in local currency?

6-35

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Data Warehouse

• •

What was the total sales volume in $ of coffee last month, compared with the total coffee sales volume in the same month last year, for the shops that have been open for at least 18 months? What is the growth of the sales volume in $ of nonfoods compared to that of foods? What is the best day of the week for total sales in the various countries? How is that related to the average? Is the best day of the week dependent on the type of location?

6-36

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Data Warehouse

• •

What products are most profitable per country? Globally? Does the service level (#employees per 1000 items sold) have influence on sales?

6-37

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Argos and Erats

"Erats have names that are unique. Erats can have argos. Argos have names as well. The name of an argo must be unique within the erat it belongs to. Erats mutually have rondels. There are only a few different types of rondels. Erats can have one or more ubins. A ubin always consists of one or more argos of the erat, one or more rondels of the erat, or combinations of the two."

6-38

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Synonym

practice - exercise order - command entity - being order - sequence order - arrangement command - demand

6-39

Copyright © Oracle Corporation, 2002. All rights reserved.

Mapping the Entity Model

Copyright © Oracle Corporation, 2002. All rights reserved.

Overview

• •

Why use design modeling? Introduction to the components:
– Tables – Columns – Constraints

• •

Basic Mapping Complex mapping

7-2

Copyright © Oracle Corporation, 2002. All rights reserved.

Why Create a Data Design Model?

• • • •

Closer to the implementation solution Facilitates discussion Ideal model can be adapted to an RDBMS model Sound basis for physical database design

7-3

Copyright © Oracle Corporation, 2002. All rights reserved.

Presenting Tables
Table: EMPLOYEES columns Id 126 349 785 Name Address Birth_date Dpt_id PAGE 12, OXFORD ST 03-03-66 10 PAPINI 53, HAYES AVE 10-08-77 20 GARRET 08-12-55 10 unique key column EMPLOYEES (EPE) Table diagram: EMPLOYEES pk * Id uk1 * Name o Address uk1 * Birth_date fk * Dpt_id foreign key column

rows

primary key column

foreign key

7-4

Copyright © Oracle Corporation, 2002. All rights reserved.

Transformation Process
Conceptual Model

Relational Model

7-6

Copyright © Oracle Corporation, 2002. All rights reserved.

Terminology Mapping
ANALYSIS
ER Model Entity Attribute Primary UID Secondary UID Relationship Business Constraints

DESIGN
Physical Design Table Column Primary Key Unique Key Foreign Key Check Constraints

7-7

Copyright © Oracle Corporation, 2002. All rights reserved.

General Naming Topics

Decide on a convention for: • Table names • Special characters (%, *, #, -, space, …) • Table short names • Column names • Primary and Unique Key Constraint names • Foreign Key Constraint names • Foreign Key Column names

7-8

Copyright © Oracle Corporation, 2002. All rights reserved.

Naming Restrictions with Oracle

Table and column names:
– Must start with a letter – May contain up to 30 alphanumeric characters – Cannot contain space or some special characters such as “!”

• •

Table names must be unique within a schema Column names must be unique within a table

7-11

Copyright © Oracle Corporation, 2002. All rights reserved.

Basic Mapping for Entities

1 - Entities Table Name: EMPLOYEES Short Name: EPE EMPLOYEE EMPLOYEES (EPE)

7-12

Copyright © Oracle Corporation, 2002. All rights reserved.

Basic Mapping for Attributes

1 - Entities 2 - Attributes Table Name: EMPLOYEES Short Name: EPE EMPLOYEE # Id * Name o Address * Birth Date EMPLOYEES (EPE) * * o * Id Name Address Birth_date

7-13

Copyright © Oracle Corporation, 2002. All rights reserved.

Basic Mapping for Unique Identifiers
1 - Entities 2 - Attributes 3 - Unique identifiers Table Name: EMPLOYEES Short Name: EPE Primary UID EMPLOYEE # Id * Name o Address * Birth Date EMPLOYEES (EPE) pk * Id uk1 * Name o Address uk1 * Birth_date

Secondary UID

7-14

Copyright © Oracle Corporation, 2002. All rights reserved.

Rules for Relationships
EMPLOYEE # Id * Name o Address * Birth Date fk2 = epe_epe_fk EMPLOYEES (EPE) pk * Id * Name fk1 * Dpt_id fk2 o Epe_id

DEPARTMENT # Id * Name

DEPARTMENTS (DPT) pk * Id fk1 = epe_dpt_fk uk * Name

7-16

Copyright © Oracle Corporation, 2002. All rights reserved.

Mapping 1:m Relationships
XS

fk

o Y_id

XS

fk

*

Y_id

7-17

Copyright © Oracle Corporation, 2002. All rights reserved.

Mapping Barred and Nontransferable Relationships
X # Id * C1 Y # Id * C2

XS (X) pk * * Id C1 fk = y_x_fk

YS (Y) * pk pk, fk * * Id X_id C2

7-19

Copyright © Oracle Corporation, 2002. All rights reserved.

Mapping Cascade Barred Relationships
A # Id * C1 B # Id * C2 C # Id * C3 D # Id * C4

AS (A) pk * Id * C1 fk = b_a_fk

BS (B) pk * Id * C2 fk,pk * A_id fk = c_b_fk

CS (C) pk * * fk,pk * fk,pk * Id C3 B_id B_a_id

DS (D) pk fk fk fk * * * * * Id C4 C_id C_b_id C_a_id

fk = d_c_fk
7-20 Copyright © Oracle Corporation, 2002. All rights reserved.

Mapping m:m Relationships

X # Id * C1

Y # Id * C2

XS pk * * Id C1 X_YS pk,fk1 * X_id pk,fk2 * Y_id fk1 = xy_x_fk

YS pk * * Id C2

fk2 = xy_y_fk

7-21

Copyright © Oracle Corporation, 2002. All rights reserved.

Mapping 1:1 Relationships
X # Id * C1 Y # Id * C2

XS (X) pk * * Id C1

YS (Y) fk = y_x_fk pk * Id * C2 fk,uk * X_id

Choose which side for FK for other cardinalities

7-22

Copyright © Oracle Corporation, 2002. All rights reserved.

Mapping Arcs
Explicit implementation USER # Id * Name ALIAS # Id fk1 = lim_x_fk USERS (USR) LIST_ITEMS (LIM) pk,fk1 * X_id fk2 o Usr_id fk3 o Als_id fk2 = lim_usr_fk pk * * Id Name

LIST ITEM

ALIASES (ALS) Id

fk3 = lim_als_fk pk * + check constraint

7-23

Copyright © Oracle Corporation, 2002. All rights reserved.

Mapping Subtypes
Variety of implementation choices P # Id * Xxx Q o Yyy R * Zzz K # Id A # Id B # Id

• • •

Supertype Subtype Both Supertype and Subtype (“Arc”)

L # Id

7-25

Copyright © Oracle Corporation, 2002. All rights reserved.

Supertype Implementation
P # Id * Xxx Q o Yyy R * Zzz K # Id A # Id B # Id PS (P) pk * * o o * o * Id Xxx Yyy Zzz A_id B_id P_type


L # Id

Mandatory discriminator column Additional constraints

fk1 fk2

7-27

Copyright © Oracle Corporation, 2002. All rights reserved.

Subtype Implementation
P # Id * Xxx Q o Yyy R * Zzz K # Id A # Id B # Id QS (Q) pk fk * Id * Xxx o Yyy * A_id q_a_fk

RS (R) pk * Id * Xxx * Zzz * A_id * B_id fk1=r_a_fk fk2=r_b_fk

L # Id

fk1 fk2

7-29

Copyright © Oracle Corporation, 2002. All rights reserved.

Supertype and Subtype (Arc) Implementation
P # Id * Xxx Q o Yyy R * Zzz PS (P) K # Id A # Id B # Id * * fk1,uk o 1 o fk2,uk *
2

pk

Id Xxx Q_id R_id A_id

fk3 = p_a_fk

fk3 fk1 = p_q_fk QS (Q) fk2 = p_r_fk RS (R) pk * Id * Zzz fk * B_id

L # Id

pk

* Id o Yyy

r_b_fk

7-31

Copyright © Oracle Corporation, 2002. All rights reserved.

P Q R

Storage Implication

1 table 2 tables 3 tables

7-33

Copyright © Oracle Corporation, 2002. All rights reserved.

Storage Implication Supertype Implementation
discriminator column cols cols cols P Q R

P Q R

rows Q

rows R

7-34

Copyright © Oracle Corporation, 2002. All rights reserved.

Storage Implication Subtype Implementation

cols P

cols R rows Q

cols P

cols Q

rows R

7-35

Copyright © Oracle Corporation, 2002. All rights reserved.

Storage Implication Supertype and Subtype (Arc) Implementation
cols P rows Q rows Q rows R rows R fk cols Q fk cols R

7-36

Copyright © Oracle Corporation, 2002. All rights reserved.

Summary

• • • •

Relational concepts Naming rules convention Basic mapping Complex mapping

7-37

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice

• • • • •

Mapping basic Entities, Attributes and Relationships Mapping Supertype Quality Check Subtype Implementation Quality Check Supertype and Subtype (Arc) Implementation Mapping Primary Keys and Columns

7-38

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Mapping basic Entities, Attributes and Relationships
EMPLOYEE # Id * First Name * Last Name * Date of Birth o Home Phone EMPLOYEES ( ) assigned to responsible for DEPARTMENT # Id * Name * Location

DEPARTMENTS (

)

7-39

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Mapping Supertype
reporting to report of DEPARTMENT report HQ COUNTRY # Id of * ORGANIZATION * Name reporting # Tax Id Number Address * Head Count to OTHER DEPARTMENT

DEPARTMENTS (

)

7-40

Copyright © Oracle Corporation, 2002. All rights reserved.

Partial ER model Moonlight
COUNTRY # Code with

PRODUCT GROUP # Name with with in PRODUCT of GLOBAL # Code LOCAL o Size # Name

with

for

PRICE LIST # Start Date * End Date with with in GLOBAL PRICE * Amount
7-41

in SHOP # No * Name * Address * City

of

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Quality Check Subtype Implementation

lpt_shop_fk GLOBAL_PRODUCTS (GPT) pk * Code o Size * Pgp_name LOCAL_PRODUCTS (LPT) pk fk fk # Name * Shop_no * Pgp_name

7-42

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Quality Check Arc Implementation
PRODUCTS (PDT) pk fk1 fk2 fk3 * * * * Code Pgp_name Gpt_code Lpt_name fk1=pdt_pgp_name fk2=pdt_gpt_code fk3=pdt_lpt_name

GLOBAL_PRODUCTS (GPT) pk * Code o Size LOCAL_PRODUCTS (LPT) pk * Name pk, fk1 o Shp_no * Pgp_name fk1

gpt_pgp_fk

fk1=shp_lpt_fk fk2=pgp_lpt_fk

7-43

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Mapping Primary Keys and Columns
GLOBAL_PRICES ( )

7-44

Copyright © Oracle Corporation, 2002. All rights reserved.

Denormalized Data

Copyright © Oracle Corporation, 2002. All rights reserved.

Overview

• • •

Denormalization Benefits Types of denormalization

8-2

Copyright © Oracle Corporation, 2002. All rights reserved.

Denormalization Overview

Denormalization • Starts with a “normalized” model • Adds “redundancy” to the design • Reduces the “integrity” of the design • Application code added to compensate

8-3

Copyright © Oracle Corporation, 2002. All rights reserved.

Denormalization Techniques

• • • • • •

Storing Derivable Values Pre-joining Tables Hard-Coded Values Keeping Details with Master Repeating Single Detail with Master Short-Circuit Keys

8-4

Copyright © Oracle Corporation, 2002. All rights reserved.

Storing Derivable Values
Before A pk * * Id X B pk,fk * A_id pk * Sequence_No * Quantity

Add a column to store derivable data in the “referenced” end of the foreign key. A After pk * Id * X * Total_quantity

8-5

Copyright © Oracle Corporation, 2002. All rights reserved.

EMail Example of Storing Derivable Values
Before USERS (USR) pk * Id * Per_name REC_MESSAGES (RME) pk,fk * Usr_Id pk,fk * Mse_Id MESSAGES (MSE) pk * * * Id Subject Text

Store derivable column in the ‘referenced’ end of the foreign key. MESSAGES (MSE) After pk * * * * Id Subject Text Number_of_times_received

8-6

Copyright © Oracle Corporation, 2002. All rights reserved.

Pre-Joining Tables
Before A pk B * Id * Col_a pk fk * * Id A_id

Add the non_key column to the table with the foreign key. B After pk fk * * * Id A_id A_col_a

8-7

Copyright © Oracle Corporation, 2002. All rights reserved.

EMail Example of Pre-Joining Tables
Before FOLDERS (FDR) pk * * Id Name RECEIVED_MESSAGES (RME) pk,fk * Mse_id pk,fk * Flr_id * Date_received

Create a table with all the frequently queried columns. RECEIVED_MESSAGES (RME) After pk,fk pk,fk * * * * Mse_id Flr_id Date_receive d Fdr_Name

8-8

Copyright © Oracle Corporation, 2002. All rights reserved.

Hard-Coded Values
Before A pk * * Id Type B pk fk * * Id A_i d

Remove the foreign key and hard code the allowable values and validation in the application. After B pk * * Id A_Type

8-9

Copyright © Oracle Corporation, 2002. All rights reserved.

Email Example of Hard-Coded Values
Before BUSINESS_TYPES (BTE) pk * Id Name USERS (USR) pk fk * * * Id Bte_id Per_name

Hard code the allowable values and validation in the application. After USERS (USR) pk * * * Id Business_type Per_name

8-10

Copyright © Oracle Corporation, 2002. All rights reserved.

Keeping Details with Master
Before A pk * Id B pk,fk * pk * * A_id Type Amount

Add the repeating detail columns to the master table. A After pk * * * * * * * Id Amount_1 Amount_2 Amount_3 Amount_4 Amount_5 Amount_6

8-11

Copyright © Oracle Corporation, 2002. All rights reserved.

EMail Example Keeping Detail with Master
Before STORAGE_QUOTAS (SQA) USERS (USR) pk * * Id Name pk,fk * pk * * * Usr_Id Storage_type Allocated Available

Add the repeating detail columns to the master table. USERS (USR) pk * Id * Name * Message_Quota_Allocated * Message_Quota_Available * File_Quota_Allocated * File_Quota_Available

After

8-12

Copyright © Oracle Corporation, 2002. All rights reserved.

Repeating Current Detail with Master
Before B A pk * Id pk,fk * A_Id Start_date pk * Price

* Add a column to the master to store the most current details. A After p * Id k * Current_price

8-13

Copyright © Oracle Corporation, 2002. All rights reserved.

Before

EMail Example of Repeating Single Detail with Master
MESSAGES (MSE) pk * Id * Subject * Text ATTACHMENTS (ATT) pk * pk,fk * * Id Mse_id Name

Add a column to the master to store the most current details.

After

MESSAGES (MSE) pk * * * * Id First_attachment_name Subject Text

8-14

Copyright © Oracle Corporation, 2002. All rights reserved.

Short-Circuit Keys
Before A pk * Id B pk fk * * Id A_id C pk * Id fk * B_id

Create a new foreign key from the lowest detail to the highest master. A After pk * Id B pk fk * * Id A_id C pk * Id fk * B_id fk * A_id

8-15

Copyright © Oracle Corporation, 2002. All rights reserved.

EMail Example of Short-Circuit Keys
Before USERS (USR) pk * Id * Name FOLDERS (FDR) pk fk * Name * Usr_id RECEIVED_ MESSAGES (RME) pk fk * * Id Fdr_name

Create a new foreign key from the lowest detail to the highest master. After USERS (USR) pk * Id uk * Name FOLDERS (FDR) pk fk * Name * Usr_id RECEIVED_ MESSAGES (RME) pk * Id fk * Fdr_name fk * Usr_name

8-16

Copyright © Oracle Corporation, 2002. All rights reserved.

End Date Column
Before B A pk * Id pk,fk pk * * A_id Start_date

Add an end date column to speed up queries so that they can use a between operator. B After pk,fk pk * *
o

A_Id Start_date End_date

8-17

Copyright © Oracle Corporation, 2002. All rights reserved.

Example of End Date Column
Before PRODUCTS (PDT) pk * * Id Name PRICES (PCE) pk,fk pk * * * Pdt_id Start_date Price

Create an extra column derivable End_date column.

After

PRICES (PCE) pk,fk pk * * *
o

Pdt_id Start_date Price End_date

8-18

Copyright © Oracle Corporation, 2002. All rights reserved.

Current Indicator Column
Before A pk * Id B pk,fk * A_id pk * Start_date

Add a column to represent the most current record in a long list of records. After B pk,fk * A_Id pk * Start_date o Current_indicator

8-19

Copyright © Oracle Corporation, 2002. All rights reserved.

Example of Current Indicator Column
Before PRODUCT (PDT) pk * * Id Name PRICES (PCE) pk,fk pk * * * Pdt_id Start_date Price

Add a column to represent the most current record, in a long list of records. PRICES (PCE) After pk,fk * Pdt_id pk * Start_date * Price o Current_indicator

8-20

Copyright © Oracle Corporation, 2002. All rights reserved.

Hierarchy Level Indicator
Before A pk fk * * Id A_id

Create a column to represent the hierarchy level of a record.

After

A pk * Id fk * A_id * Level_no

8-21

Copyright © Oracle Corporation, 2002. All rights reserved.

Example of Hierarchy Level Indicator
Before FOLDERS (FDR) pk * Id fk * Fdr_id * Name Create a column to represent the hierarchy level of a record.

After

FOLDERS (FDR) pk * fk * * * Id Fdr_id Name Level_no

8-22

Copyright © Oracle Corporation, 2002. All rights reserved.

Denormalization Summary
Denormalization Techniques • Storing Derivable Information
– End Date Column – Current Indicator – Hierarchy Level Indicator

• • • • •

Pre-Joining Tables Hard-Coded Values Keeping Detail with Master Repeating Single Detail with Master Short-Circuit Keys

8-23

Copyright © Oracle Corporation, 2002. All rights reserved.

Practices

• • • •

Name that Denormalization Triggers Denormalize Price Lists Global Naming

8-24

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Name that Denormalization (1/3)

WEEKDAYS (WDY) pk * * Code Name

SHIFTS (SFT) pk * No fk Wdy_code * Start_time * End_time * Wdy_name *

8-25

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Name that Denormalization (2/3)

PROD_GRPS (PGP) pk * Name

PRODUCTS (PDT) pk fk * Code * Pgp_Name

PROD_NAMES (PNE) pk * fk * fk * Name Pdt_code Pgp_name

8-26

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Name that Denormalization (3/3)

PRICE_LISTS (PLT) COUNTRIES (CTY) pk * Code * Name pk,fk pk * * o * Cty_code Start_date End_date Current_price_ind

8-27

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Triggers (1/6)
ORDER_HEADERS (OHR) pk * * Id Order_total ORDER_ITEMS (OIM) pk * Ohr_id pk * Seqno * Item_total

8-28

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Triggers (2/6)
Table OHR Trg Type Insert Delete Update Id Order_total OIM Insert Delete Update Ohr_id Item_total Column Needed? What should it do?

8-29

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Triggers (3/6)
LOCATIONS (LCN) pk * * Id Address EMPLOYEES (EPE) pk * Id fk * Lcn_id * Name * Lcn_address

8-30

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Triggers (4/6)
Table LCN Trg Type Insert Delete Update Address other cols EPE Insert Delete Update Lcn_id Lcn_address Column Needed? What should it do?

8-31

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Triggers (5/6)
PRODUCTS (PDT) pk * * Id Name PRICES (PCE) pk * Pdt_id pk * Start_date o End_date * Curr_price_ind

8-32

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Triggers (6/6)

Table Trg Type Column PDT Insert Delete PCE Insert Delete Update Pdt_id Start_date End_date Curr_price_Ind

Needed? What should it do?

8-33

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Denormalize Price Lists

• •

Speed up performance for queries on Amount. Insert new price lists before their effective date.
PRICE_LISTS (PLT) pk * Start_date pk,fk * Cty_code GLOBAL_PRICES (GPE) pk,fk * Plt_start_date pk,fk Plt_cty_code * Amount *

8-34

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Global Naming
LANGUAGES (LGE) pk * Code * Name

Track a corporate name for each product.

PRODUCTS (PDT) pk * Code o Size

PRODUCT_NAMES (PNE) pk,fk * Pdt_code pk,fk Lge_code * Name *

8-35

Copyright © Oracle Corporation, 2002. All rights reserved.

Database Design Considerations

Copyright © Oracle Corporation, 2002. All rights reserved.

Overview

• • • •

Oracle specific Design Considerations Data Integrity Issues Performance Considerations Storage Issues

9-2

Copyright © Oracle Corporation, 2002. All rights reserved.

Why Adapt Data Design?

User Expectations

• • • •

Volumes Hardware Network O.S. Initial design Adapted Physical Design

Oracle specifics

9-3

Copyright © Oracle Corporation, 2002. All rights reserved.

Oracle Data Types

Depending on: • Domains • Storage issue • Performance • Use Select a data type for columns: • Character • Number • Date • Large Objects

9-4

Copyright © Oracle Corporation, 2002. All rights reserved.

Suggested Column Sequence

• • • • •

Primary key columns Unique Key columns Foreign key columns Mandatory columns Optional columns Large object columns always at the end

9-6

Copyright © Oracle Corporation, 2002. All rights reserved.

Primary Keys
CREATE TABLE countries ( code , name , currency ); ALTER TABLE countries ADD CONSTRAINT cty_pk PRIMARY KEY (code); Constraint and Index name NUMBER(6) VARCHAR2(25) NUMBER (10,2) NOT NULL NOT NULL NOT NULL

9-7

Copyright © Oracle Corporation, 2002. All rights reserved.

Primary Keys

Choosing the Right Key • Simplicity • Ease of use • Performance • Size • Meaningless • Stability

9-9

Copyright © Oracle Corporation, 2002. All rights reserved.

Artificial Keys
AS (A) pk * Id * C1 fk1 = d_a_fk BS (B) pk * Id * C2 fk2 = d_b_fk DS (D) u ,fk1 * A_id pk u ,fk2 * B_id pk u ,fk3 * C_id pk * C4 pk * Id CS (C) pk * Id * C3 fk3 = d_c_fk

XS (X) pk fk1 fk1 fk fk1 * * ** *
o

Id D_a_id fk = x_d_fk D_b_id D_id D_c_id C5

9-11

Copyright © Oracle Corporation, 2002. All rights reserved.

Sequences

225 224

223

CREATE SEQUENCE sequence_name INCREMENT BY number START WITH number MINVALUE number MAXVALUE number CACHE number | NOCACHE CYCLE | NOCYCLE;

9-13

Copyright © Oracle Corporation, 2002. All rights reserved.

Foreign Key Behavior

Delete Restrict Cascade

Update

Default Nullify

Supported by Oracle through declaration

9-14

Copyright © Oracle Corporation, 2002. All rights reserved.

Indexes
• Performance
Name ALBERT ALFRED ALICE ALLISON ALVIN ALPHONSO Phone
b c d

2655 3544 7593 3456 8642 2841

ef gh ij kl m no pq rs tu vw xyz

• Uniqueness
9-16 Copyright © Oracle Corporation, 2002. All rights reserved.

Choosing Indexes
B*tree Bitmap aba .1.2.5 Reverse abb .1.4.5 bba .1.3.5 cba .1.1.5 ... X 0 1 0 1 0 Y 1 0 0 0 0 Z 0 0 1 0 1

aba .1.2.5 abb .1.3.5 abc .1.1.5 bba .1.4.5 ...

C1 C2 aba X abb Z abc Y bba Z bbc X
9-17

I.O.Table

C1 C2 abc Y aba X abb Z bba X bbc Z

Copyright © Oracle Corporation, 2002. All rights reserved.

Which Columns to Index?

• • •

Primary key columns and Unique Key columns (Up to Version 6) Foreign Key columns When significant better performance can be observed in SELECT statements

!
• •

Avoid indexing:

Small tables Columns frequently updated

9-19

Copyright © Oracle Corporation, 2002. All rights reserved.

When Can Indexes be Used?

• • • •

When referenced in a Where clause or Order By When the Where clause does not include some operators When the optimizer decides With hints in the SQL statement

9-21

Copyright © Oracle Corporation, 2002. All rights reserved.

Partitioning Tables and Indexes
CUSTOMERS Col1 Col2 Col3 Region

CUSTOMERS_R1 Col1 Col2 Col3 Region

CUSTOMERS_R2 Col1 Col2 Col3 Region

9-22

Copyright © Oracle Corporation, 2002. All rights reserved.

Views

• • • • •
T1

Restricting access Presentation of data Isolate applications from data structure Save complex queries Simplify user commands
T2 T3 T4

V1
9-23

V2

V3

V4

Copyright © Oracle Corporation, 2002. All rights reserved.

Reasons for Views

Advantages
– Dynamic views – Present denormalized data from normalized tables – Simplify SQL statements

Disadvantages
– May affect performances – Restricted DML in some cases

9-24

Copyright © Oracle Corporation, 2002. All rights reserved.

Old Fashioned Design

• • •

Unique index Views with “Check option” clause Generic Arc implementation

9-25

Copyright © Oracle Corporation, 2002. All rights reserved.

Generic Arc Implementation
A # Id * Name X # Id * Name Y # Id * Name

AS (A) ... * Table_name * Fk_id

(X or Y)

9-26

Copyright © Oracle Corporation, 2002. All rights reserved.

Distributed Database

Different physical databases appear as one logical database.

9-27

Copyright © Oracle Corporation, 2002. All rights reserved.

Benefits of Distributed Databases

• • • • • but •

Resilience Reduced line traffic Location transparency Local autonomy Easier growth path Increased, distributed, complexity

9-28

Copyright © Oracle Corporation, 2002. All rights reserved.

DATABASE

Database Structure

consists of part of TABLESPACE consists of resides part of in container of

SEGMENT
OTHER SEGMENT TABLE INDEX SEGMENT SEGMENT consists of part of FREE

residence of DATA FILE consists of

sliced in sliced in located in part of part of TABLE OR INDEX PARTITION EXTENT USED resides in residence of

part of DATA BLOCK

9-29

Copyright © Oracle Corporation, 2002. All rights reserved.

Summary

• • • • • •

Data Types Primary, Foreign, and Artificial Keys Indexes Partitioning Views Distributed design

9-31

Copyright © Oracle Corporation, 2002. All rights reserved.

Practices

• • •

Data Types Artificial Keys Product Pictures

9-32

Copyright © Oracle Corporation, 2002. All rights reserved.

CURRENCY of COUNTRY # Code # Code with with in in from to EXCHANGE RATE # Month * Rate

Moonlight Pricing with

PRODUCT GROUP # Name with in PRODUCT of

in

for GLOBAL LOCAL PRICELIST # Code # Name # Start Date o Size with * End Date of with with with LOCAL PRICE # Start Date in of o End Date GLOBAL of * Amount PRICE * Amount PRODUCT NAME * Name
Copyright © Oracle Corporation, 2002. All rights reserved.

with SHOP # No * Name * Address * City

LANGUAGE # Code of in

9-33

Data Types (1)
Table COUNTRIES CURRENCIES EXCHANGE_RATES PRICE_LISTS PRODUCT_GROUPS PRODUCTS Column Code Code Month Rate Start_date End_date Name Code Size Pdt_type Suggested Data Type Varchar2(2) Varchar2(3) Date Number(8,4) Date Date Char(8) Char(10) Number(4,2) Number(1) Your Choice Data Type

9-34

Copyright © Oracle Corporation, 2002. All rights reserved.

Data Types (2)
Table GLOBAL_PRICES LOCAL_PRICES SHOPS Column Amount Start_date End_date Amount Name Address City Your Choice Data Type

9-35

Copyright © Oracle Corporation, 2002. All rights reserved.

Solutions

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Instance or Entity?
Concept
PRESIDENT ELLA FITZGERALD DOG ANIMAL HEIGHT TYPE OF TRANSPORT Number of Wheels My current car

E/A/I? Example Instance or Entity
E I E E A E A I Lincoln, Washington, Gorbachev STAR, SINGER, PERSON Snoopy Cat, Dog, ... PERSON, BUILDING, ... CAR CAR CAR

A-2

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Guest
Address Arrival Date Family Name GUEST HOTEL ROOM Room Number Floor Number Number of Beds Number of Parking Lots Price TV set available?

A-3

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Reading

EMPLOYEE

assigned to responsible for

DEPARTMENT

A Each EMPLOYEE may be assigned to one or more DEPARTMENTS
Each DEPARTMENT must be responsible for one or more EMPLOYEES

B Each EMPLOYEE must be assigned to one or more DEPARTMENTS
Each DEPARTMENT may be responsible for one or more EMPLOYEES

C Each EMPLOYEE must be assigned to exactly one DEPARTMENT
Each DEPARTMENT may be responsible for exactly one EMPLOYEE

A-4

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Read and Comment
PERSON born in birthplace of living in home town of visitor of visited by mayor of governed by (as mayor) TOWN

A-5

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Hotel
HOTEL * Address location for owned located in by ROOM * Room Number location for taking place in STAY * Arrival Date favored by known by

owner of

aware in favor of of PERSON * Name

endured by enduring

A-6

Copyright © Oracle Corporation, 2002. All rights reserved.

Ralph’s Raving Recipes Soups

Açorda alentejana
bread soup from Portugal for 4 persons: 1 onion 4 cloves of garlic 1 red pepper 1 liter of vegetable broth 4 tablespoons of olive oil 4 fresh eggs 1 handful of parsley or coriander salt, pepper 9-12 slices of (old) bread Cut the onion into small pieces and fry together with the garlic. Wash the red pepper, cut it in half, remove the seeds and fry it for at least 15 page 127

vegetarian 15 min easy

preparation

A-7

Copyright © Oracle Corporation, 2002. All rights reserved.

Ralph’s Raving Recipes Soups

Açorda alentejana
bread soup from Portugal for 4 persons: 1 onion 4 cloves of garlic 1 red pepper 1 liter of vegetable broth 4 tablespoons of olive oil 4 fresh eggs 1 handful of parsley or coriander salt, pepper 9-12 slices of (old) bread Cut the onion into small pieces and fry together with the garlic. Wash the red pepper, cut it in half, remove the seeds and fry it for at least 15 page 127

vegetarian 15 min easy

preparation

A-8

Copyright © Oracle Corporation, 2002. All rights reserved.

BOOK Solution: Recipe -Title a RECIPE must be classified in containing exactly one RECIPE GROUP published in A RECIPE GROUP may be RECIPE classification for one or more -Name RECIPES -Description -Vegetarian? -Number of People classified in RECIPE -Preparation Time GROUP -Preparation Ease classification -Name -Preparation Text for prepared used with in INGREDIENT -Name -Quantity -Unit -Type
A-9

a RECIPE must be prepared with one or more INGREDIENTS An INGREDIENT may be used in exactly one RECIPE

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Books
MANUSCRIPT TRANSLATION TITLE EDITION PRINTING VERSION COPY LANGUAGE

A-10

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Books
MANUSCRIPT TRANSLATION TITLE EDITION PRINTING VERSION COPY LANGUAGE

A-11

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Moonlight
COUNTRY COUNTRY COMMUNITY CURRENCY DEPARTMENT DRINK EMPLOYEE EXCHANGE RATE FOOD JOB LOCATION TYPE PASTRY PRODUCT PRODUCT GROUP PRICE SALE SHOP STOCK OPTION STOCK PRICE TICKER SYMBOL

A-12

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Shops
SHOP in * Number of * Name * Location * City located o Telephone in * Open Date of or COUNTRY * Code * Name of in LOCATION * Name located in of LOCATION TYPE * Description COUNTRY * Code * Name

LOCATION TYPE * Description

SHOP * Number * Name located o Telephone in * Open Date of
A-13

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Subtypes
DISABLED PERSON DEAF AND BLIND DEAF, NOT BLIND BLIND, NOT DEAF OTHER DISABLED BUILDING HOUSE OTHER SEDAN OTHER CAR CAR STATION WAGON

HOTELROOM ROOM WITH BATH OTHER ROOM

DOG
r pai DOMESTIC re nd ANIMAL eyo b MAMMAL

A-14

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Schedule (1/2)
SHOP * Name * Location * City with for SCHEDULE prepared by * Start Date maker * End Date of with withi n SCHEDULE ENTRY * Weekday * Shift Number EMPLOYEE * Family Name * First Name * Short Name

for with

A-15

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Schedule (2/2)
with within SCHEDULE ENTRY * Monday Shift * Tuesday Shift * Wednesday Shift * Thursday shift * Friday Shift * Saturday Shift * Sunday Shift for with

A-16

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Address
PERSON Address text line1 Address text line2 Address text line3 Address text line4

1

COUNTRY

2

PERSON Street or “PO Box” Indicator Street House Number City Post Code Province or State

ADDRESS TYPE

COUNTRY

A-17

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Read the Relationship
ALU of with BRY Every ALU must be of exactly one BRY Every BRY may be with one or more ALUS

Every PUR may be bazooned in one or more YOKS Every YOK may be bazooned by one or more PURS bilought in glazoed with

PUR

bazooned in bazooned by

YOK

KLO

HAR

Every KLO must be bilought in one or more HARS Every HAR may be glazoed with exactly one KLO

A-19

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Find a Context
COUNTRY birthplace of born in location of located in PERSON FEMALE mother of son of most popular movie star in COUNTRY with most popular movie star born in birthplace of mother of PERSON MALE MALE FEMALE child of TOWN PERSON

PERSON

A-20

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Name the Intersection Entity
PRODUCT in of SALE * Date DEPARTMENT STORE with at

PERSON in of

SAILBOAT with at

INTERPRETER with

LANGUAGE with in

CREW MEMBERSHIP * Role

of FLUENCY * Score

A-21

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Receipt
Served by: Dennis Till: 3 Dec 8, 4:35 pm ----------------------CAPPUCC M 3.60 * 2 7.20 CREAM .75 * 2 1.50 APPLE PIE 3.50 BLACKB MUF 4.50 <SUB> 16.70 tax 12% 2.00 <TOTAL> 18.70 ======= CASH 20.00 RETURN 1.30 ----------------------Hope to serve you again @MOONLIGHT COFFEES 25 Phillis Rd, Atlanta
A-22 Copyright © Oracle Corporation, 2002. All rights reserved.

COUNTRY * Name with in SHOP * Name o VAT% with in TILL * Number

PERSON * First Name with with at at SALES HEADER * Date & Time * Amount Cash with

PRODUCT * Short Name * Price in referring to

part of SALES ITEM * Quantity
A-23

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Moonlight P&O (1)
All Moonlight Coffee employees work for a department such as “Global Pricing” or “HQ”, or for a shop. All employees are at the payroll of one of our country organizations. Jill, for example, works as a shop manager in London; Werner is a financial administrator working for Accounting and is located in Germany … DEPARTMENT * Name with SHOP * Name * City with COUNTRY ORGANIZATION with

works works for for EMPLOYEE * Name * Job

at payroll of

A-24

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Moonlight P&O (2)
reporting to DEPARTMENT * Name OTHER DEPARTMENT report of HQ report of reporting to COUNTRY ORGANIZATION with

… All shops belong with to one country with belongs organization (“the to countries”). There SHOP is only one country * Name organization per * City country. All with works countries and works for for departments report EMPLOYEE to HQ, except HQ * Name itself … * Job
A-25 Copyright © Oracle Corporation, 2002. All rights reserved.

on payroll of

Solution: Moonlight P&O (3)
reporting to DEPARTMENT * Name … Employees can work part time. Lynn has had an 80% assignment for Product Development since the 1st September. Before that she had a full-time position. OTHER DEPARTMENT with with at payroll of EMPLOYEE * Name with to ASSIGNMENT * Job * Start Date * Part Time % of report of HQ Report of reporting to COUNTRY ORGANIZATION with belongs to SHOP * Name * City with to

A-26

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Moonlight P&O (4)
4a: COUNTRY ORGANIZATION with EMPLOYEE with for PAYROLL ENTRY * Start Date for COUNTRY in ORGANIZATION of with 4d belongs to 4e: SHOP * No * Name
Copyright © Oracle Corporation, 2002. All rights reserved.

reporting to 4c DEPARTMENT * Name OTHER DEPARTMENT

report of HQ report of

4b

COUNTRY * Name of located in

A-27

Solution: Price List
COUNTRY * Currency in SHOP * Name * Address * City with at PRICE LIST * Start Date * End Date with in PRICE * Amount with PRODUCT GROUP with in PRODUCT * Short Name o Size with coffees teas foods nonfoods supplements

of

A-29

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: EMail
USER owner of 1 owned by referred to for 4 forwarded with COMPOSITION NICK NAME containing within 2 FOLDER

USER owner of owned owned by by LIST FOLDER

3 is forward of

owner containing of within

A-30

Copyright © Oracle Corporation, 2002. All rights reserved.

USER 5

owner of owned by LIST owner of owned by 6

USER

owner of owned by LIST owner of owned by is referred to referring to

is referred to referring to

is referred to is referred to referring to referring to

LIST ITEM

LIST ITEM o External User owner of NICK NAME owned by o For External User referred to for

USER 7

A-31

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Holiday (1)
“Paul and I hiked in the USA. Eric and I hiked in France and we rented a car in the USA last year”. COUNTRY France USA USA
CO Fr U US an NT US A ce RY A

TRANSPORT Boots Boots Car TRANSPORT
TR Bo AN Ca ot SP O Bo r s RT ot s

COUNTRY

A-32

Copyright © Oracle Corporation, 2002. All rights reserved.

CO Er M E r ic P A NI P a ic O N ul

CO Er M COMPANION Er ic PA NI Pa ic O ul N

Solution: Holiday (2)
COUNTRY France France USA USA USA COMPANION Eric Eric Eric Eric Paul TRANSPORT Boots Car Boots Car Boots

A-33

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Holiday (3)
COUNTRY France USA COMPANION Eric Paul TRANSPORT Boots Car

COUNTRY

COMPANION

TRANSPORT

HOLIDAY

COUNTRY France USA USA

COMPANION Eric Eric Paul

TRANSPORT Boots Car Boots

A-34

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Normalize an ER Model: Solution
offered by COURSE DEPARTMENT ENROLLMENT #* course number #* department code completed course name department name the with offerer of for taught by the receiver the of assigned to receiver of assigned GRADE TEACHER #* grade code #* teacher number STUDENT grade description teacher name #* student id for last name first name

A-35

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Identification 1
1 A # Xx B * Yy C # Zz

A 2 C # Code

B # Id

3

A * Xx B # Yy C # Zz with of D # Id

A-37

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Identification 2
4 P Q # Id 5 P # Name

PERSON MALE # Seqno 6

son of

FEMALE mother of # Name # Birth Date partner in with wife

partner in with husband MARRIAGE # Start Date

A-38

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Moonlight UID
reporting to DEPARTMENT # Name OTHER DEPARTMENT with EMPLOYEE # Id with for of report of HQ report of

reporting to in of

COUNTRY with ORGANIZATION with

COUNTRY # Code with located in

for PAYROLL ENTRY # Start Date

assigned SHOP to # No with to as

for to ASSIGNMENT # Start Date
A-40

in

JOB # Title

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Table
USER owner of in FOREIGN KEY # Name from to with referenced in with with for ASSOCIATION # Seqno from in in COLUMN # Name in * Data Type o Not Null for USAGE # Seqno owner of in with TABLE # Name owner of in with of with of UNIQUE KEY # Name PRIMARY

in of

to

A-41

Copyright © Oracle Corporation, 2002. All rights reserved.

1

Solution: Constraints
managed by

EMPLOYEE # Name OTHER CEO EMPLOYEE manager of

2
USER # Name owned by owner of with subfolder

ALIAS # Name LIST NICKNAME

3

within owner of owned by

FOLDER # Name

USER # Name

A-42

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Shift
SHOP * Name with WEEKDAY # Code * Name with on SHIFT # No * Start Time * End Time on on SHIFT SCHEDULE with or on SHIFT SCHEDULE * Start Date with CALENDAR DAY # Date * Public Holiday Indicator of starting starting on

A-43

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Moonlight Pricing
COUNTRY # Code with PRODUCT GROUP # Name with in PRODUCT of with with in

for GLOBAL LOCAL PRICE LIST # Code # Name # Start Date o Size with * End Date of with with with LOCAL PRICE # Start Date in of o End Date GLOBAL PRICE of * Amount * Amount PRODUCT NAME * Name
A-44

SHOP # No * Name * Address * City

LANGUAGE # Code of in

Copyright © Oracle Corporation, 2002. All rights reserved.

1

PRODUCT GROUP PRODUCT BUNDLE

2

PRODUCT GROUP

BUNDLE with

PRODUCT

in of referring to BUNDLE ITEM * Quantity PRODUCT Needed GROUP 3 PRODUCT

OTHER PRODUCT with

in of referring BUNDLE ITEM * to Quantity Needed

ASSEMBLY ITEM * Quantity Needed

A-45

Copyright © Oracle Corporation, 2002. All rights reserved.

DecafPunch (DP) = {Coffee (C) or Tea (T)} and {Blackberry Muffin (BM)} PRODUCT GROUP # Name Consider this as: AS1 = (C or T) DP = (AS1 and BM)

PRODUCT # Code o And/Or Indicator

PRODUCTS Code And_or C T AS1 OR DP AND ASSEMBLY ITEMS Prod_code AS1 AS1 DP DP

Pg_name .. … …. …..

ASSEMBLY ITEM * Quantity Needed

Using_code Quantity 1 C T 1 1 AS1 1 BM

A-46

Copyright © Oracle Corporation, 2002. All rights reserved.

1

LEVEL1 fixed number of levels with LEVEL2 PRODUCT CLASS # Name

LEVEL3

or generic:

within

LEVEL4 2 LEVEL5 product + coffees + teas + foods + nonfoods + supplements + bundles

PRODUCT

A-47

Copyright © Oracle Corporation, 2002. All rights reserved.

Patterns

• • • • • •

Model of moves in a chess game Model of quotations Model of recipes Model of all people involved in college: students, teachers, parents, … Rentals in a video shop Model of phases in a process

Chain or Network M/D or Basket Bill of Material Roles

M/D or Basket Chain or Network

A-48

Copyright © Oracle Corporation, 2002. All rights reserved.

Patterns

• • • • • •

Model of moves in a chess game Model of quotations Model of recipes Model of all people involved in college: students, teachers, parents, … Rentals in a video shop Model of phases in a process

Chain or Network M/D or Basket Bill of Material Roles

M/D or Basket Chain or Network

A-49

Copyright © Oracle Corporation, 2002. All rights reserved.

Moonlight Data Warehouse
YEAR # No with in with

QUARTER with assigned with in to PRODUCT MONTH WEEK CLASS # No # No with with with of in in PRODUCT DAY # Id # No with in of of SALES VOLUME * Quantity * Value in Local Currency * Value in $

within with GEOGRAPHY * Number of Inhabitants * Number of Employees wit of h within

A-50

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Argos and Erats
ERAT # Name have have of RONDEL * Type in with UBIN ITEM Constraint not shown: A ubin always consists of one or more argos of the erat, one or more...
A-51 Copyright © Oracle Corporation, 2002. All rights reserved.

have of

have belongs of to UBIN ARGO # Name with with

unknown optionality unknown degree

in with

Solution: Synonym
MEANING # Id * Description shared by with WORD # Word MEANINGS Id Description 1 Action, actual doing ... 2 Regular arrangement ... 3 Order, command ... 4 A vehicle with two wheels 5 ...

synonym WORDS Word Mng_i Practice d Exercise 1 Order 1 Sequence 2 Arrangement 2 Order 2 Command 3 Demand 3 Bike 3 4

homonym

A-52

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Mapping basic Entities, Attributes and Relationships

DEPARTMENTS (DPT) pk * Id * Name o Location

EMPLOYEES (EPE) pk * Id epe_dpt_fk fk * Dpt_id * Last Name * First Name o Home Phone

A-53

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Mapping Supertype
dpt_dpt_fk DEPARTMENTS (DPT) pk * * * * o o fk Id Name Dpt_type Headcount Address Dpt_id_reporting_to

A-54

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Mapping Supertype
dpt_dpt_fk DEPARTMENTS (DPT) pk * * * * o o fk Id Name Dpt_type Headcount Address Dpt_id_reporting_to

A-55

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Quality Check Subtype Implementation

gpt_pgp_fk GLOBAL_PRODUCTS (GPT) pk * Code o Size fk * Pgp_name

lpt_shp_fk LOCAL_PRODUCTS (LPT) pk * Name pk,fk * Shp_no * Pgp_name fk

A-56

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Quality Check both Supertype and Subtype Implementation
PRODUCTS (PDT) pk * Code fk1 * Pgp_name fk2, uk1 o Gpt_code fk3, uk2 o Lpt_name fk3, uk2 o Lpt_shp_no pk * Code o Size LOCAL_PRODUCTS (LPT) fk3=pdt_lpt_fk pk * Name pk, fk * Shp_no lpt_shp_fk fk1=pdt_pgp_fk fk2=pdt_gpt_fk

GLOBAL_PRODUCTS (GPT)

A-57

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Primary Keys and Columns

GLOBAL_PRICES (GPE) pk, fk1 * pk, fk1 * pk, fk2 * * Plt_cty_code Plt_start_date Gpt_code Amount

fk1= gpe_plt_fk fk2= gpe_gpt_fk

A-58

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Triggers (1/6)
ORDER_HEADERS (OHR) pk * * Id Order_total ORDER_ITEMS (OIM) pk * Ohr_id pk * Seqno * Item_total

A-60

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Triggers (2/6)
Table OHR Trg Type Insert Delete Update Id Order_total OIM Insert Delete Update Ohr_id Item_total Column Needed? What should it do? Y N N Y Y Y Y Y prevent update recalculate Order_total recalculate Order_total recalculate Order_total recalculate Order_total Order_total := 0

A-61

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Triggers (3/6)
LOCATIONS (LCN) pk * * Id Address EMPLOYEES (EPE) pk * Id fk * Lcn_id * Name * Lcn_address

A-62

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Triggers (4/6)
Table LCN Trg Type Insert Delete Update Address other cols EPE Insert Delete Update Lcn_id Column Needed? What should it do? N N Y Y Y N Y Set correct Lcn_address Prevent update Cascade to Employees If pk updated than extended cascade Set correct Lcn_address

Lcn_address Y

A-63

Copyright © Oracle Corporation, 2002. All rights reserved.

Practice: Triggers (5/6)
PRODUCTS (PDT) pk * * Id Name PRICES (PCE) pk * Pdt_id pk * Start_date o End_date * Curr_price_ind

A-64

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Triggers (6/6)
Table Trg Type Column PDT Insert Delete PCE Insert Delete Update Pdt_id Start_date End_date Needed? What should it do? N N Y N Y Y Y Set Curr_price_ind to NULL Re-evaluate Curr_price_ind Re-evaluate Curr_price_ind Prevent update by user Prevent overlap in price periods

Curr_price_Ind Y

A-65

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Denormalize Price Lists

PRICE_LISTS (PLT) pk pk,f k * Start_date * Cty_code * End_date

GLOBAL_PRICES (GPE) pk,fk * Plt_start_date pk,fk * Plt_cty_code * Amount * Current_indicator

A-66

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Denormalize Global Naming
LANGUAGES (LGE) pk * Code * Name

PRODUCTS (PDT) pk * o * Code Size Corporate_Name

PRODUCT_NAMES (PNE) pk,fk * Pdt_code pk,fk Lge_code * Name *

A-68

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Data Types (1)
Table COUNTRIES CURRENCIES EXCHANGE_RATES PRICE_LISTS PRODUCT_GROUPS PRODUCTS Column Code Code Month Rate Start_date End_date Name Code Size Pdt_type Suggested Data Type Varchar2(2) Varchar2(3) Date Number(8,4) Date Date Char(8) Char(10) Number(4,2) Number(1)

Your Choice Data Type?
Char(2) Char(3) Number(2) Number(12,4)

Date Date
Varchar2(15) Varchar2(15) Char(1) Char(3)

A-69

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Data Types (2)
Table GLOBAL_PRICES LOCAL_PRICES SHOPS Column Amount Start_date End_date Amount Name Address City Your Choice Data Type Number(15,3) Date Date Number(15,3) Varchar2(50) Varchar2(50) Varchar2(50)

A-70

Copyright © Oracle Corporation, 2002. All rights reserved.

Solution: Product Pictures

PRODUCTS (PDT) pk * Code …….

TEXT_DOCUMENTS (TDT) pk,fk * Pdt_code varchar2(3) pk varchar2(20) * Info_type o Information CLOB

BINARY_DOCUMENTS (BDT) pk,fk * Pdt_code varchar2(3) pk varchar2(20) * Info_type o Information BLOB

A-72

Copyright © Oracle Corporation, 2002. All rights reserved.

Normalization

Copyright © Oracle Corporation, 2002. All rights reserved.

Overview

• •

Table Normalization Normal Forms of Tables

B-2

Copyright © Oracle Corporation, 2002. All rights reserved.

Why Normalize?

• • • •

An Entity Model is not always available as a starting point for design. To reduce redundant data in existing design. To increase integrity of data, and stability of design. To identify missing tables, columns and constraints.

Note: Third normal form is the generally-accepted goal for a database design that eliminates redundancy.

B-4

Copyright © Oracle Corporation, 2002. All rights reserved.

Recognize Unnormalized Data
USER _ID ---2301 2301 2301 5607 5607 5607 7773 7773 0022 0022 USER _NAME ----Smith Smith Smith Jones Jones Jones Walsh Walsh Patel Patel MSE _ID ----54101 54098 54445 54101 54512 54660 54101 54554 54101 54512 REC_ DATE ----05/07 07/12 10/06 05/07 06/07 12/01 05/07 03/17 05/07 06/07 SRVR _ID ---3786 3786 3786 6001 6001 6001 9988 9988 2201 2201 SERVER _NAME -----IMAP05 IMAP05 IMAP05 IMAP08 IMAP08 IMAP08 EMEA01 EMEA01 EMEA09 EMEA09

SUBJECT --------------Meeting Today Promotions Next Assignment Meeting Today Lunch? Jogging Today? Meeting Today Stock Quote Meeting Today Lunch?

TEXT ---------There is.. I like to. Your next. There is.. Can you... Can you... There is.. The latest There is.. Can we ...

B-5

Copyright © Oracle Corporation, 2002. All rights reserved.

Normalization Rules
Normal Form Rule First Normal Form (1NF) Description The table must express a set of unordered, two-dimensional tables. The table cannot contain repeating groups. The table must be in 1NF. Every non-key column must be dependent on all parts of the primary key. The table must be in 2NF. No non-key column may be functionally dependent on another non-key column.

Second Normal Form (2NF)

Third Normal Form (3NF)

“Each non-primary key value MUST be dependent on the key, the whole key, and nothing but the key.”

B-6

Copyright © Oracle Corporation, 2002. All rights reserved.

Converting to First Normal Form
USER _ID ---2301 2301 2301 5607 5607 5607 7773 7773 0022 0022 USER _NAME ----Smith Smith Smith Jones Jones Jones Walsh Walsh Patel Patel MSE _ID ----54101 54098 54445 54512 54101 54660 54101 54554 54101 54512 REC_ DATE ----05/07 07/12 10/06 06/07 05/07 12/01 05/07 03/17 05/07 06/07 SRVR SUBJECT TEXT _ID --------------- --------------Meeting Today There is.... 3786 Promotions I like to... 3786 Next Assignment Your next... 3786 Lunch? Can you..... 6001 Meeting Today There is.... 6001 Jogging Today? Can you..... 6001 Meeting Today There is.... 9988 Stock Quote The latest.. 9988 Meeting Today There is.... 9988 Lunch? Can we ..... 9988 SERVER _NAME -----IMAP05 IMAP05 IMAP05 IMAP08 IMAP08 IMAP08 EMEA01 EMEA01 EMEA01 EMEA01

1. Remove repeating group from the base table. 2. Create a new table with the PK of the base table and the repeating group.

B-7

Copyright © Oracle Corporation, 2002. All rights reserved.

First Normal Form - Single Record
USERS USER USER MSE REC_ SRVR SERVER _ID _NAME _ID DATE SUBJECT TEXT _ID _NAME ---- ----- ----- ----- ------------- ---------- ---- -----2301 Smith 54101 05/07 Meeting Today There is.. 3786 IMAP05 5607 Jones 54512 06/07 Lunch? Can you... 6001 IMAP08

7773 Walsh 54101 05/07 Meeting Today There is.. 9988 EMEA01 0022 Patel 54101 05/07 Meeting Today There is.. 9988 EMEA01 USER _ID ---2301 5607 7773 0022 USER _NAME ----Smith Jones Walsh Patel SRVR _ID ---3786 6001 9988 9988 SERVER _NAME -----IMAP05 IMAP08 EMEA01 EMEA01

USERS

B-8

Copyright © Oracle Corporation, 2002. All rights reserved.

First Normal Form - Repeating Groups
USER RECEIVED_ _ID MESSAGES ---(1NF) 2301 2301 2301 5607 5607 5607 7773 USER USER 7773 SRVR _ID _NAME 0022 _ID 0022 ---- ----- ---2301 Smith 3786 5607 Jones 6001 7773 Walsh 9988 0022 Patel 9988 MSE REC_ _ID DATE SUBJECT ----- ----- --------------54101 05/07 Meeting Today 54098 07/12 Promotions 54445 10/06 Next Assignment 54101 05/07 Meeting Today 54512 06/07 Lunch? 54660 12/01 Jogging Today? 54101 05/07 Meeting Today 54554 03/17 Stock Quote SERVER 54101 05/07 Meeting Today _NAME 54512 06/07 Lunch? -----IMAP05 IMAP08 USERS (1NF) EMEA01 EMEA01 TEXT ---------There is.. I like to. Your next. There is.. Can you... Can you... There is.. The latest There is.. Can we ...

B-9

Copyright © Oracle Corporation, 2002. All rights reserved.

Converting to Second Normal Form

1. Determine which non-key columns are not dependent upon the table’s entire primary key. 2. Remove those columns from the base table. 3. Create a second table with those columns and the columns from the PK that they are dependent upon.

B-10

Copyright © Oracle Corporation, 2002. All rights reserved.

Tables Already in Second Normal Form

USERS

USER _ID ---2301 5607 7773 0022

USER _NAME ----Smith Jones Walsh Patel

SRVR _ID ---3786 6001 9988 9988

SERVER _NAME -----IMAP05 IMAP08 EMEA01 EMEA01

Is the USERS table already in 2NF?

B-11

Copyright © Oracle Corporation, 2002. All rights reserved.

Convert to Second Normal Form
RECEIVED_ MESSAGES (1NF) RECEIVED_ MESSAGES (2NF) USER MSE _ID _ID ---- ----2301 54101 2301 54098 2301 54445 5607 54101 5607 54512 5607 54660 7773 54101 7773 54554 0022 54101 0022 54512 USER MSE REC_ _ID _ID DATE SUBJECT TEXT ---- ----- ----- -------------- --------2301 54101 05/07 Meeting Today There is. 2301 54098 07/12 Promotions I like to 2301 54445 10/06 Next Assignment Your next 5607 54101 05/07 Meeting Today There is. 5607 54512 06/07 Lunch? Can you.. REC_5607 54660 12/01 Jogging Today? Can you.. DATE7773 54101 05/07 Meeting Today There is. 7773 54554 03/17 Stock Quote The lates ----0022 54101 05/07 Meeting Today There is. 05/07 0022 54512 06/07 Lunch? Can we .. 07/12 10/06 MESSAGES MSE 05/07 _ID SUBJECT TEXT (2NF) 06/07 ----- ------------ --------12/01 54101 Meeting Toda There is. 05/07 54098 Promotions I like to 03/17 54445 Next Assignm Your next 05/07 54512 Lunch? Can you.. 06/07 54660 Jogging Toda Can you.. 54554 Stock Quote The lates

B-12

Copyright © Oracle Corporation, 2002. All rights reserved.

Converting to Third Normal Form

Remove any columns that are dependent upon another non-key column: 1. Determine which columns are dependent upon another non-key column. 2. Remove those columns from the base table. 3. Create a second table with those columns and the non-key columns that they are dependent upon.

B-13

Copyright © Oracle Corporation, 2002. All rights reserved.

Tables Already in Third Normal Form
No non-key column can be functionally dependent upon another non-key column.
RECEIVED_ MESSAGES (2NF) USER _ID ---2301 2301 2301 5607 5607 5607 7773 7773 0022 0022
B-14

MSE _ID ----54101 54098 54445 54101 54512 54660 54101 54554 54101 54512

REC_ DATE ----05/07 07/12 10/06 05/07 06/07 12/01 05/07 03/17 05/07 06/07

MESSAGES (2NF) ID SUBJECT TEXT ----- -------------- --------54101 Meeting Today There is. 54098 Promotions I like to 54445 Next Assignment Your next 54512 Lunch? Can you.. 54660 Jogging Today? Can you.. 54554 Stock Quote The lates Are these two tables in third normal form? Why?

Copyright © Oracle Corporation, 2002. All rights reserved.

Converting to Third Normal Form
USERS ID ---2301 5607 7773 0022 NAME ----Smith Jones Walsh Patel SRVR _ID ---3786 6001 9988 9988

USERS USER _ID ---2301 5607 7773 0022 USER _NAME ----Smith Jones Walsh Patel SRVR _ID ---3786 6001 9988 9988 SERVER _NAME -----IMAP05 IMAP08 EMEA01 EMEA01

MAIL_ ID SERVER ---3786 6001 9988

NAME -----IMAP05 IMAP08 EMEA01

B-15

Copyright © Oracle Corporation, 2002. All rights reserved.

Summary
1NF The table must express a set of unordered, twodimensional tables. The table cannot contain repeating groups. 2NF The table must be in 1NF. Every non-key column must be dependent on all parts of the primary key. 3NF The table must be in 2NF. No non-key column may be functionally dependent on another non-key column. An entity relationship model transforms into normalized data design.

B-16

Copyright © Oracle Corporation, 2002. All rights reserved.

Sign up to vote on this title
UsefulNot useful