You are on page 1of 18

CS 338: Computer Applications in Business: Databases (Fall 2014)

The Relational
Model & Relational
Database
Constraints
Chapter 3

Fall 2014

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.)

CS 338: Computer Applications in Business: Databases


Rice University Data Center

Questions & Review

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

CS 338: Computer Applications in Business: Databases (Fall 2014)

Review
Database Users
Define different types of database users.
Professional Users:

Database Administrators
Database Designers
System Analysts
Application Programmers

End Users

Casual
Parametric
Sophisticated
Standalone

-maybe one request per day, not very many


-many requests per day
-know what they are doing, make specific applications to access DB
-use some software that uses a database in the background
3

Review
Advantages of DBMS

List some advantages of using a DBMS.

Controlling redundancy

Restricting unauthorized access

Efficient Execution of queries and updates

Efficient search techniques

Backup and recovery

Multiple user interfaces

Representing complex relationships among data

Enforcing integrity constraints

Permitting inferencing and actions using rules


4

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

CS 338: Computer Applications in Business: Databases (Fall 2014)

Review
Data Models
What is a data model?
A set of concepts to describe the structure of a database, and certain
constraints that the database should follow

What are the different categories of data models that exist?


Conceptual (high-level, semantic)
Representational (Implementation)
Physical (low-level, internal)

What are the basic concepts that make up a conceptual model?


Entity

Attribute

Relationship
5

Review
Representational Data Models

List different types of representational data model.


Relational

represents database as a collection of tables

Object

defines a database in terms of objects, properties and


operations

XML

combines database concepts with concepts from


document representation models

Network
Hierarchical

Old and not commonly used today


6

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

CS 338: Computer Applications in Business: Databases (Fall 2014)

Review
Terminologies

What is a database schema?


The description of a database, database structure, data types, and
constraints

What is database state?


The actual data in a database at a particular moment in time

What is DDL?
Data Definition Language: language used to define database schemas

What is DML?
Data Manipulation Language: language used to manipulate (retrieve,
insert, delete, and modify data)

Relational Data
Model Concepts
Chapter 3

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

CS 338: Computer Applications in Business: Databases (Fall 2014)

Relational Data Model Concepts


Relational Model
Proposed by Dr. E. Codd of IBM Research in the 1970 in the following paper
"A Relational Model for Large Shared Data Banks, Communications of the
ACM, June 1970
Revolutionary idea

The first commercial implementations available in early 1980s

Based on the concept of a Relation

Relation is a mathematical concept based on the idea of sets


Represents data as a collection of relations

Relational Data Model Concepts

Data as a collection of relations

A relation is similar to a table of values (informal)


Typically contains a set of rows
Row

Data elements in each row represent certain facts that typically


correspond to a real-world entity or relationship
In formal model, rows are called Tuples

Column
Each column has a column header
Gives some meaning of the data items in that column
In formal model, column header is called an attribute name (or
simply an attribute)

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

10

CS 338: Computer Applications in Business: Databases (Fall 2014)

Relational Data Model Concepts

11

Formal Definition - Schema


The relation schema (or description) of a Relation
denoted by R(A1, A2, ...,An)
A relation is composed of
relation name R and a list of attributes: A1, A2, ..., An

Example
PRODUCTS (UPC, Title, Price, Quantity)
PRODUCTS is the relation name
Defined over four attributes: UPC, title, price and quantity
Domain

Each attribute has a domain or a set of valid (atomic) values


Denoted by dom(An)
Example: the domain of UPC is 12-digit numbers
The domain may have a data type and/or format

A degree (or arity) of a relation is the number of


attributes n of its relation schema

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

12

CS 338: Computer Applications in Business: Databases (Fall 2014)

Formal Definition State & Tuple


A relation (or relation state) r of the relation schema R(A1, A2, ...,An)
denoted by r(R)
is a set of n-tuples r = {t1, t2, , tm}

Tuple
A tuple is an ordered set of values t = <v1, v2, , vn>
Each value vi, 1 , ( )
( )

Example

A row in the PRODUCTS relation is 4-tuple consisting of four


values. For instance: <0088590934387, iPhone 4, $399.99, 10>
This is called a 4-tuple as it has 4 values
A tuple (or row) in PRODUCTS relation

Cardinality of a relation is the number of tuples m of a


relation (or total number of values in a domain)
13

Formal Definition State (revisited)


A relation state r(R) is
is a mathematical relation of degree n on the domains
dom(A1), dom(A2), dom(An), which is a subset of the
Cartesian product (denoted by ) of the domains of its
attributes that define R

[?] == X



)
The Cartesian product specifies all possible combinations of
values from underlying domains

Product of cardinalities of all domains represents the total number


of possible instances or tuples that ever exist in any relation state
r(R)
Of all these possible combinations, a relation state at a given time
the current relation state reflects only valid tuples that
represent a particular state of the real world
14

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

CS 338: Computer Applications in Business: Databases (Fall 2014)

Formal Definition - Summary


Formally
Given R(A1, A2, , An)

R(A1, A2, , An)


R
A1, A2, , An
r(R)

is the relation schema


is the name of the relation
are the attributes of the relation
a specific state of relation R
this is a set of valid tuples

r(R) = {t1, t2, , tm}


t = < v1, v2, vn >

Each n-tuple t is an ordered list of n values


Each value vi is an element of dom(Ai)

15

Example 1
Formal Definition
Let R(A1, A2) be a relation schema
Let dom(A1) = {1, 2, 3}
Let dom(A2) = {a, b, c}


possible combinations

is all

{<1,a>,<1,b>,<1,c>,<2,a>,<2,b>, <2,c>,<3,a>, <3,b>,<3,c>}


The relation state
)
Any subset of the Cartesian product is a relation
For example: r(R) could be {<1,a>, <1, b>, <2,c>} where it
1
a
has three 2-tuple
1

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

16

CS 338: Computer Applications in Business: Databases (Fall 2014)

Example 2
Formal Definition
Assume we have the following sets:

dom(Name) = {John, Joanna}


dom(Country) = {USA, Canada}
dom(Course) = {MATH, CSCI}

If we denote the total number of values or cardinality, in a


domain dom by |dom|, the total number of tuples in the
Cartesian product is

| = 2 x 2 x 2 = 8

= {

(John, USA, MATH)


(John, USA, CSCI)
(John, Canada, MATH)
(John, Canada, CSCI)
(Joanna, USA, MATH)
(Joanna, USA, CSCI)
(Joanna, Canada, MATH)
(Joanna, Canada, CSCI)
17

Example 2
Formal Definition
Now there could be some subset out of the 8 pairs that we
only need (relation state)
The relation schema R(Name, Country, Course)
Let us assume the subset
{ (John, USA, MATH), (Joanna, Canada, CSCI) }

which is a subset of the Cartesian product that reflects only valid tuples
that represent a particular state of the real world

r(R) = { (John, USA, MATH), (Joanna, Canada, CSCI) }


Now this is our relation or table
NAME

COUNTRY

COURSE

John

USA

MATH

Joanna

Canada

CSCI
18

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

CS 338: Computer Applications in Business: Databases (Fall 2014)

Example 2
Formal Definition
Now there could be some subset out of the 8 pairs that we
only need (relation state)
Attributes

COUNTRY
USA

COURSE
ENGR

Joanna

Canada

CSCI

Tuples

Cardinality

Relation

NAME
John

Degree

19

Definition Summary

20

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

10

CS 338: Computer Applications in Business: Databases (Fall 2014)

Example
A relation STUDENT

21

Characteristics of Relations
1

Ordering of tuples in a relation r(R):


The tuples are not considered to be ordered, even though
they appear to be in the tabular form
There is no preference for one ordering over another

22

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

11

CS 338: Computer Applications in Business: Databases (Fall 2014)

Characteristics of Relations
2

Ordering of values within a tuple and an alternative


definition of a relation
Order of attributes and values is not that important
As long as correspondence between attributes and values
maintained

We will consider the attributes in R(A1, A2, ...,An) and the values in
t=<v1, v2, ..., vn> to be ordered

An alternative definition: making the ordering of values


in a tuple unnecessary
Tuple considered as a function from attributes to values
tj : {A1, A2, A3, , An} dom(A1) dom(A2) dom(An)
Use notation tj[Ai] or tj.Ai to refer to tuples value vi from dom(Ai)
Similarly, tj[Au, Aw, ..., Az] and tj.(Au, Aw, ..., Az) refer to the subtuple of values <vu, vw, ..., vz> from tj for attributes Au, Aw, ..., Az
Therefore, a tuple is a set of <attribute, value> pairs

23

Characteristics of Relations
2

Ordering of values within a tuple and an alternative


definition of a relation

Example:
attendee(id, givenName, surname, company, dateOfBirth)
t = <10483, John, Doe, IBM, 1978-11-05>
t[id] = 10483, t[givenName] = John, t[surname] = Doe,
etc
t.id = 10483, t.givenName = John, t.surname = Doe, etc
t = { <id, 10483>, <givenName, John>, <surname, Doe>,
<company, IBM>, <dateOfBirth, 1978-11-05> }
24

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

12

CS 338: Computer Applications in Business: Databases (Fall 2014)

Characteristics of Relations
3

Values and NULLs in tuples


Flat relational model: Composite and multivalued
attributes not allowed

Each value in a tuple is atomic (cannot be decomposed further)

Each value in a tuple must be from the domain of


attributes for that column
If tuple t <v1, v2, , vn> is a tuple (row) in the relation
state r of R(A1, A2, An), then each vi must be a value
from dom(Ai)
A special NULL value is used to represent values that are
unknown or inapplicable to certain tuples
Several meanings for NULL

value unknown, value exists but is not available, or attribute does


not apply to this tuple (value undefined)

Characteristics of Relations
3

25

Values and NULLs in tuples


If an attribute for a tuple is mapped to NULL, we cannot
make any assumption about the value for that attribute
(for that tuple)
e.g., Ashleys telephone number is NULL could mean

Ashley doesnt have a phone

Ashley has a phone but we dont know the number (perhaps


withheld)

Ashley may or may not have a phone, but regardless we dont


have a number for Ashley
26

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

13

CS 338: Computer Applications in Business: Databases (Fall 2014)

Characteristics of Relations
4

Interpretation (meaning) of a relation


Assertion

The relation schema can be interpreted as a declaration or a type


of assertion

Example: schema of the STUDENT relation asserts that, in


general, a student entity has a Name, Ssn, Home_phone, Address,
Office_phone, Age, and Gpa

Each tuple in the relation is a fact or a particular instance of the


assertion

27

Characteristics of Relations
4

Interpretation (meaning) of a relation


An alternative interpretation of a relation schema is as a
Predicate

Values in each tuple interpreted as values that satisfy predicate

Example: predicate STUDENT (Name, Ssn, ) it true for the five


tuples in relation STUDENT

These tuples represent five different propositions or facts in the


real world

28

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

14

CS 338: Computer Applications in Business: Databases (Fall 2014)

Relational Model Notation

Uppercase letters Q, R, S denote relation names


Corresponding lowercase letters q, r, s denote
corresponding relation states
Uppercase letters A, B, C, , H denote attributes
Attribute A can be qualified with the relation name R
to which it belongs using the dot notation
e.g., R.A
Lower case letters t, u, v denote tuples
29

Relational Databases and


Relational Database Schemas
Relational database schema S
A set S of relation schemas that belong to the same
database
S is the name of the whole database schema
Set of relation schemas S = {R1, R2, ..., Rm} and a set of
integrity constraints (IC)
R1, R2, Rm are the names of the individual relation
schemas within the database schema S

30

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

15

CS 338: Computer Applications in Business: Databases (Fall 2014)

Relational Databases and


Relational Database Schemas

Relational database state


Set of relation states DB = {r1, r2, ..., rm}
Each ri is a state of Ri and such that the ri relation states
satisfy integrity constraints
Invalid state
Does not obey all the integrity constraints
Valid state
Satisfies all the constraints in the defined set of integrity
constraints IC

31

Relational Databases and


Relational Database Schemas

32

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

16

CS 338: Computer Applications in Business: Databases (Fall 2014)

Using Your Clicker


Turn it on:
Press the ON/OFF button. A solid blue light should appear next to the top Power
button. If your clicker came wrapped in packaging, pull out the small plastic tab on the
back to activate the batteries.

Change the frequency to AA:


The instructions on the back of your clicker say
Press and hold the ON/OFF button until the top blue Power light flashes. Enter the 2 letter
frequency code (AA).

The code for each classroom (AA for DWE 1501) is posted near the podium at the front
of the class. When a clicker is turned off it forgets any changes in frequency and the
clicker frequency is again AA when the clicker is turned on.

How do I know if my vote has been received?


When the receiver acknowledges a vote, the Vote Status light on the clicker (the third
light) will flash green for a moment. If it flashes red instead, then either the voting
period hasn't started, or the receiver didn't respond to your vote. In the latter case,
change the frequency of your clicker if necessary and vote again. Raise your hand for
assistance if you don't see a green response.

Can I change my vote/choice?


Yes. While the voting process is active, you can vote as often as you like. Only your last
(most recent) choice/vote is recorded.
33

Practice Clicker Question A

What faculty are you in?


A:

Applied Health Sciences

B:

Arts

C:

Environment

D:

Mathematics

E:

Science or Engineering

34

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

17

CS 338: Computer Applications in Business: Databases (Fall 2014)

Practice Clicker Question B

What year are you in?


A:

B:

C:

D:

E:

none of the above

35

1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning
Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.),
Database System Concepts (5/6) (Silberschatz et al.), Database Systems (9/10) (Coronel et al.)

18

You might also like