Sunteți pe pagina 1din 6

Relational Data Model


Relations are stored in tables
Relational Databases – e.g. Sponsor(Senator,Bill)
Sponsor Atrributes
CPSC 315 – Programming
Senator Bill
Studio
Smith Tax
Fall 2010
Jones Defense
Project 1, Lecture 2 Smith Defense
Tuples

Slides adapted from those used by Adams Commerc


Jeffrey Ullman, via Jennifer Welch e

Converting from Entity-


Schemas Relationship Model

A relation schema is a relation name ●
ER: Entity set -> relation
and a list of attributes – ER Attributes become Relational attributes
– Sponsor(Senator,Bill) ●
ER: Relationship -> relation

A database is a collection of relations – Keys of connected ER entity sets become

A database schema is the set of all Relational attributes
the relation schemas in the database
ER Entity Sets Relations

Senator(Name,Party,State,Years)
Name ●
Bill(Name,Text)
Party
Senator Organization

Lobbyist(Name,Organization)
State Lobbyist

Name
Years

Bill

Name Text

ER Relationships Relations

Sponsored(Senator,Bill)
Name

Wrote(Bill,Lobbyist)
Contributed

Contributed(Senator,Lobbyist)
Party Organization
Senator

State Lobbyist

Remember, each of these is expressed as a
table (with the columns given by the
Years Sponsored
Name “parameters”)
Wrote ●
Notice that columns can refer to “bigger”
Bill
items, with even more attributes

Name Text
Combining Relations Combining Relations

Relations can sometimes be combined. ●
Example (many-to-one): (Good)
– Person(Name, Birthdate, Height, Weight, Eye

Assume a “base” entity set with its Color, Hair Color)
relation. – BornIn(Person,Town)

If there is a many-to-one relation, that – Person(Name, Birthdate, Height, Weight, Eye
can be combined with the base entity Color, Hair Color, Town)
set. ●
Example(many-to-many): (Bad)
– Senator(Name, Party, State, Years)

Should not combine many-to-many – Sponsored(Senator, Bill)
– Redundancy – each of the many stored – Senator(Name, Party, State, Years, Bill)

Weak Entity Sets Weak Entity Set Example



The relation for a weak entity set must
contain all the elements of its key First
Name
Last
Name
Number
Note arrrow:

Supporting relationships are usually indicates many
to one.
redundant (unless possibly multi-way) Baseball Player Position

Birthdate

Plays
Team
Nationality Salary On

City Name
Weak Entity Set Example Weak Entity Set Example

Team(Name, City) ●
Team(Name, City)

Baseball Player(Number, TeamName,

Baseball Player(Number, TeamName,
First Name, Last Name, Position, First Name, Last Name, Position,
Birthdate, Nationality, Salary) Birthdate, Nationality, Salary)

Note that we don’t need
PlaysOn(BaseballPlayer.Number,
BaseballPlayer.TeamName,
Team.Name)

Weak Entity Set Example Weak Entity Set Example



Team(Name, City) ●
Team(Name, City)

Baseball Player(Number, TeamName, ●
Baseball Player(Number, TeamName,
First Name, Last Name, Position, First Name, Last Name, Position,
Birthdate, Nationality, Salary) Birthdate, Nationality, Salary)

Note that we don’t need
PlaysOn(BaseballPlayer.Number,

Note that we don’t need
BaseballPlayer.TeamName, PlaysOn(BaseballPlayer.Number,
Team.Name) BaseballPlayer.Team.Name)
Redundant (same)
Subclasses
Weak Entity Set Example Different Options

Team(Name, City) ●
Different ways to represent subclasses

Baseball Player(Number, TeamName, Name

First Name, Last Name, Position, Elected Official

Party
Birthdate, Nationality, Salary)

Note that we don’t need isa

PlaysOn(BaseballPlayer.Number, U.S.
District
BaseballPlayer.Team.Name) Representative

Already
Included

Object-Oriented Style Entity-Relationship Style



One relation for each subset, including ●
One relation for each subclass
all “inherited” attributes (including key)
Elected Official Elected Official
Name Party U.S. Representative Name Party U.S. Representative
Chet Edwards Democrat Name Party District Chet Edwards Democrat Name District
Chet Democrat 17 Chet Edwards 17
John Cornyn Republican Edwards John Cornyn Republican
Ron Paul 14
John Adams Federalist Ron Paul Republican 14 John Adams Federalist
Ron Paul Republican Ron Paul Republican
Using Nulls Style Keys

One relation total, with nulls for unknown ●
A Key “functionally determines” all
information
U.S. Representative
other attributes of the relation
Name Party District – Given a relation and a key, there is only
Chet Democrat 17 one tuple that corresponds to it
● Edwards
● John Cornyn Republican NULL

There are subtle differences from an E-
John Adams Federalist NULL
Ron Paul Republican 14
R key, which we won’t go into.


Can save space, but problematic if multiple
subclasses or lots of NULLs

S-ar putea să vă placă și