0% found this document useful (0 votes)
3 views

DB03

The document provides an overview of the Relational Data Model, including its structure, components, and the process of converting Entity/Relationship (E/R) diagrams into relational schemas. It discusses the creation of relations from entity sets and relationships, as well as the handling of weak entity sets and isa hierarchies. Additionally, it highlights the importance of SQL as a powerful query language for relational databases.

Uploaded by

Waqas Raja
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

DB03

The document provides an overview of the Relational Data Model, including its structure, components, and the process of converting Entity/Relationship (E/R) diagrams into relational schemas. It discusses the creation of relations from entity sets and relationships, as well as the handling of weak entity sets and isa hierarchies. Additionally, it highlights the importance of SQL as a powerful query language for relational databases.

Uploaded by

Waqas Raja
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

COMP5531 Files & Databases

Relational Data Model


Conceptual Database Design
Relational Data Model:
Introduction
The Relational Data Model
◼ Relational database
◼ A set of relations
◼ Relation
◼ A two-dimensional table in which data is arranged
Example: Relation
Attribute Names

Title Year Length FilmType


Star Wars 1997 124 color
Mighty Ducks 1991 104 color
Wayne’s World 1992 95 color
... ... ... ...
Each row
is a tuple Components of the tuple
Attributes (type) are atomic (1NF)
Relational Data Model
◼ Relation schema (or structure): Ri={A1,…,Am}
◼ Relation name + a set of attribute names (+ attribute types)
◼ Relation instance:
◼ The set of “current” tuples
◼ Database schema:
◼ A set of relation schemas D={R1,…,Rn}
◼ Database instance:
◼ A collection of relation instances -- one for each relation in the
database schema
Relational Query Languages
◼ A major strength of the relational model is that it
supports a powerful, high-level programming
language – the Structured Query Language (SQL)
Logical Database Design
From E/R to Relational Model
Converting E/R to Relational Model
◼ Input:
◼ An E/R diagram
◼ Output:
◼ A relational database schema -- a collection of relations
Converting Entity Sets to Relations
◼ For each entity set E, create a corresponding relation with
the same attributes as in E
Entity Set: Relation Instance:
courseNumber name courseNumber name credits
Comp248 C++ Prog. 3
Courses
Comp352 Data Structures 4
Comp353 Databases 4
credits
Relation Schema:
In theory, Courses = {courseNumber, name, credits}
In practice, Courses(courseNumber, name, credits)
Converting Entity Sets to Relations
Entity Set: Relation Instance:
lastName firstName ID firstName lastName GPA address
111 Joe Smith 4.0 45 Pine av.
ID Students
222 Sue Brown 3.1 71 Main St.
333 Ann John 3.7 39 Bay St.
GPA address

Relation Schema:
Students(ID, firstName, lastName, GPA, address)
Converting Entity Sets to Relations
Entity Set: Relation Instance:
title year title year length filmType
Star Wars 1997 124 color
Movies Mighty Ducks 1991 104 color
Wayne’s World 1992 95 b&w
length filmType
Relation Schema:
Movies(title, year, length, filmType)
Converting Entity Sets to Relations
Entity Set: Relation Instance:
name address
name address
Fox Hollywood
Studios Disney Hollywood
Paramount Hollywood

Relation Schema:
Studios(name, address)
Converting Relationships to Tables
◼ For each relationship set R, create the corresponding table (relation)
and determine its attributes.
◼ The set of attributes of this table includes:
◼ “Implicitly”: Key attribute(s) of the entity sets involved in the relationship R
◼ “Explicitly”: every attribute used ”explicitly” in R
From Relationships to Tables
Relationship Set:
lastName firstName courseNumber name

ID Students EnrolledIn Courses

GPA address grade credits

Relation Instance:
Relation Schema: ID courseNumber grade
123 Comp248 A-
EnrolledIn (ID, courseNumber, grade)
456 Comp248 B
What is the primary key of this relation? 123 Comp353 A+
From Relationships to Tables
Relationship Set:

courseNumber name DID name

Courses GivenBy Departments

credits address
Relation Instance:
Relation Schema: courseNumber DID
Comp248 1
GivenBy(courseNumber, DID)
Comp352 1
What is the primary key of this relation? Math207 9
From Relationships to Tables
Relationship Set:
lastName firstName ID name

ID Professors Chair Departments

address
researchArea address
Relation Instance:
Relation Schema: PID DID
Chair(PID, DID) 234 1
451 2
What is the primary key of this relation? 778 9
Identifying Key of Relationship R
◼ We are already familiar with the concept of key
◼ If R is a binary relationship between entity sets E1 and E2, then the
multiplicity of this relationship determines the key of R
◼ If R is M-N, then the keys of E1 and E2 together are “part of” the key of R
◼ If R is M-1 from E1 to E2, then the key of E1 is part of the key of R
◼ If R is 1-1, then either E1 or E2 (but not both) is part of the key of R
◼ Do the above rules regarding the formation of keys apply to:
◼ Multi-way relationships?
◼ How to determine keys for:
◼ Weak entity sets?
◼ Entity sets and relationship sets in isa hierarchies?
Converting Relationships to Tables
◼ We should rename the attributes in the relations created
when:
◼ An entity set is involved in a relationship more than once
◼ The same attribute name appears in the keys of different entity
sets involved in the relationship (e.g., ID in previous example)
◼ This is to avoid ambiguity in the schema and to be more clear
in meanings
Relationship Sets to Relations
Relationship Set: name address

Studios
Producing Studio
studio of star
title year name address
Movies Contracts Stars

length filmType salary


Relation Schema: What is the primary key for Contracts?

Contracts(starName, title, year, studioOfStar, producingStudio, salary )


Weak Entity Sets to Relations
◼ The relation/table W for the weak entity setW, must
include all the attributes ofW as well as the key attributes
of the strong entity sets to whichW is associated.
◼ Any relationship R to which the weak entity setW
contributes, must include all the key attributes of W, i.e.,
the key attributes of every entity set that contributes to
W’’s key
◼ The weak relationships, from the weak entity setW to
other entity sets that provide the key forW, need not be
converted into a separate table, i.e., double diamonds
connecting a weak entity set need not become a separate
table.
Weak Entity Sets to Relations
Weak Entity Set:

number name address

Crews Unit-of Studios

Relation Schema:
Do we need to keep the
Crews (number, name) relation Unit-of?
Unit-of (number, studioName, name)
Studios (name, address)
Weak Entity Sets to Relations
Weak Entity Set:

number number name address

Sub-Crews Part-of Crews Unit-of Studios

Relation Schemas:
Sub-Crews (number,crewNumber, name)
Studios (name, address)
Weak Entity Sets to Relations
name address
Weak Entity Set:
Studios
Producing Studio
studio of star
Contracts

Movie-of salary Star-of


title year

Movies name address


Stars
length filmType
What is the key for Contracts?
Relation Schema:
Contracts(starName, title, year, studioOfStar, producingStudio,salary)
Converting isa-Hierarchies to Relations
There are 3 approaches:
◼ Straight-E/R style method
◼ In the E/R model, an entity (object) can be represented by
entities that may belong to several entity sets, which are
connected and related via isa hierarchies
◼ The “connected” entities together represent the object and also
determine the object’s properties (e.g., attributes and
relationships)

◼ The object-oriented method


◼ The nulls method
Converting isa-Hierarchy to Relations
◼ For each entity set E, create a relation (table) e, and give it
attribute(s) A, whenever:
◼ A belongs to E
◼ A is the key attribute of the parent(s) relation

◼ No relation is created for the isa-relationship


Isa-Hierarchy to Relations
lastName firstName
Isa-hierarchy:
to Professor ID Students

isa
isa GPA address
SupervisedBy
major
option
GradStudents UgradStudents

Relation Schemas: Students (ID, lastName, firstName, GPA, address )


GradStudents (ID, option )
UgradStudents (ID, major )
SupervisedBy (StudentID, professorID)
Isa-Hierarchy to Relations
title year

Movies
to Stars
isa
isa length filmType
Voices
weapon
Murder-
Cartoons
Mysteries
Relation Schemas: Movies (title, year, length, film Type)
Cartoons (title, year)  Do we really need this?
What about
Cartoon-Murder-Mysteries? Murder-Mysteries (title, year, weapon)
Voices (starName, title, year)
The NULL Values Approach
◼ If we are allowed to use NULL as a value in tuples, we can
handle a hierarchy of entity sets (classes) with a single
relation
◼ This relation has all the attributes belonging to any entity set (class)
of the hierarchy.
◼ An entity/object is represented by a single tuple that has NULL in
each attribute that is not defined for that entity/object.
Converting isa Hierarchy to Relations:
The Null Approach
isa hierarchy: lastName firstName

to Professor ID Students

isa
isa GPA address
SupervisedBy
major
option
GradStudents UgradStudents
Relation Schemas:
SupervisedBy (ID, professorID)
Student (ID, lastName, firstName, GPA, address, option, major)
NULL Approach
◼ The null approach: supports efficient query processing but is
inefficient in space utilization. Why?
◼ Answering queries: the nulls approach allows us to find, in a single
relation R, every tuple/object from any set involved in the hierarchy
◼ Allows us to find all the information about an entity/object in a
single tuple in R
◼ The down side is its space utilization which is too costly for having
repeated and redundant information:
◼ Note: Nulls are not allowed in the relational model theory,
but practically, it is supported by commercial DBMS
A quick test!
◼ Suppose R is a M-1 relationship from entity set
E1={a1, a2} to E2={b1, b2}. Which of the following is
NOT a valid instance of R?
◼ R = {(a1, b1), (a1, b2)}.
◼ R = {(a1, b1)}.

◼ R = {(a2, b1)}.

◼ R = {(a1, b1), (a2, b1)}.

◼ R={}

You might also like