Top Banner
1 CS 338: Computer Applications in Business: Databases (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 (9/10) (Coronel et al.) CS 338: Computer Applications in Business: Databases The Relational Model & Relational Database Constraints ©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.) Rice University Data Center Fall 2014 Chapter 3 Questions & Review 2
18
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 03_Relational Data Model Concepts

1

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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

The Relational Model & Relational Database Constraints

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.) Rice University Data Center

Fall 2014

Chapter 3

Questions & Review

2

Page 2: 03_Relational Data Model Concepts

2

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

Review Database Users…

• Professional Users:• Database Administrators• Database Designers• System Analysts• Application Programmers

• End Users• Casual• Parametric• Sophisticated• Standalone

3

Define different types of database users.Define different types of database users.

Review Advantages of 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

List some advantages of using a DBMS.List some advantages of using a DBMS.

Nathan Wilson
-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
Nathan Wilson
Nathan Wilson
Page 3: 03_Relational Data Model Concepts

3

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

Review Data Models…

A set of concepts to describe the structure of a database, and certain constraints that the database should follow

5

What is a data model?What is a data model?

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

What are the different categories of data models that exist?What are the different categories of data models that exist?

Entity Attribute Relationship

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

Review Representational Data Models…

6

List different types of representational data model.List different types of representational data model.

Relational represents database as a collection of tables

Objectdefines a database in terms of objects, properties and operations

XMLcombines database concepts with concepts from document representation models

Network Old and not commonly used today

Hierarchical

Page 4: 03_Relational Data Model Concepts

4

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

Review Terminologies…

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

7

What is a database schema?What is a database schema?

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

What is database state?What is database state?

Data Definition Language: language used to define database schemas

What is DDL?What is DDL?

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

What is DML?What is DML?

Relational Data Model ConceptsChapter 3

8

Page 5: 03_Relational Data Model Concepts

5

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

Relational Data Model Concepts

9

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

Relational Model

• The first commercial implementations available in early 1980s

Revolutionary idea…

• Relation is a mathematical concept based on the idea of sets• Represents data as a collection of relations

Based on the concept of a Relation

Relational Data Model Concepts

10

• A relation is similar to a table of values (informal)• Typically contains a set of rows

Data as a collection of relations…

• 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

Row

• 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)

Column

Page 6: 03_Relational Data Model Concepts

6

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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

Relational Data Model Concepts

A degree (or arity) of a relation is the number of attributes n of its relation schema

Formal Definition - Schema

12

• denoted by R(A1, A2, ...,An)• A relation is composed of

• relation name R and a list of attributes: A1, A2, ..., An

The relation schema (or description) of a Relation

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

Example

• 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

Domain

Page 7: 03_Relational Data Model Concepts

7

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

Cardinality of a relation is the number of tuples m of a relation (or total number of values in a domain)

Formal Definition – State & Tuple

13

• denoted by r(R)• is a set of n-tuples r = {t1, t2, …, tm}

A relation (or relation state) r of the relation schema R(A1, A2, ...,An)

• A tuple is an ordered set of values t = <v1, v2, …, vn>• Each value vi, 1 ≤ 𝑖 ≤ 𝑛, 𝑖𝑠 𝑎𝑛 𝑒𝑙𝑒𝑚𝑒𝑛𝑡 𝑜𝑓 𝑑𝑜𝑚(𝐴𝑖) 𝑜𝑟 𝑖𝑠 𝑎 𝑠𝑝𝑒𝑐𝑖𝑎𝑙

𝑁𝑈𝐿𝐿 𝑣𝑎𝑙𝑢𝑒 (𝑤𝑖𝑙𝑙 𝑏𝑒 𝑑𝑖𝑠𝑐𝑢𝑠𝑠𝑒𝑑 𝑙𝑎𝑡𝑒𝑟)

Tuple

• 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

Example

Formal Definition – State (revisited)…

14

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

• 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

A relation state r(R) is …

𝑟 𝑅  ⊆ �  𝑑𝑜𝑚 𝐴 �  𝑑𝑜𝑚 𝐴 �  … �    𝑑𝑜𝑚 𝐴 )

Nathan Wilson
Nathan Wilson
[?] == X
Nathan Wilson
Page 8: 03_Relational Data Model Concepts

8

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

Formal Definition - Summary

15

• Given R(A1, A2, …, An)

• R(A1, A2, …, An) is the relation schema• R is the name of the relation• A1, A2, …, An are the attributes of the relation• r(R) a specific state of relation R

this is a set of valid tuples

• r(R) = {t1, t2, …, tm} Each n-tuple t is an ordered list of n values• t = < v1, v2, … vn > Each value vi is an element of dom(Ai)

Formally…

𝒓 𝑹  ⊆ �  𝒅𝒐𝒎 𝑨𝟏 �  𝒅𝒐𝒎 𝑨𝟐 �  … �    𝒅𝒐𝒎 𝑨𝒏 )

Example 1 Formal Definition

16

• Let dom(A1) = {1, 2, 3}• Let dom(A2) = {a, b, c}

{<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

has three 2-tuple

Let R(A1, A2) be a relation schema

𝒕𝒉𝒆𝒏    𝒅𝒐𝒎 𝑨𝟏 �  𝒅𝒐𝒎 𝑨𝟐 �  … �    𝒅𝒐𝒎 𝑨𝒏 is all possible combinations

1 a

1 b

2 c

Page 9: 03_Relational Data Model Concepts

9

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

Example 2 Formal Definition

17

• 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

Assume we have the following sets:

�  𝑑𝑜𝑚 𝐴   �    𝑑𝑜𝑚 𝐴  �� �  𝑑𝑜𝑚 𝐴 | = 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)

Example 2 Formal Definition

• 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

Now there could be some subset out of the 8 pairs that we only need (relation state)

NAME COUNTRY COURSE

John USA MATHJoanna Canada CSCI

18

Page 10: 03_Relational Data Model Concepts

10

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

Example 2 Formal Definition

Now there could be some subset out of the 8 pairs that we only need (relation state)

NAME COUNTRY COURSEJohn USA ENGRJoanna Canada CSCI

Relation

Attributes

Degree

Tuples

Cardinality

19

Definition Summary

20

Page 11: 03_Relational Data Model Concepts

11

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

Example A relation STUDENT

21

Characteristics of Relations

22

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

1

Page 12: 03_Relational Data Model Concepts

12

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

Characteristics of Relations

23

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 tuple’s value vi from dom(Ai)• Similarly, tj[Au, Aw, ..., Az] and tj.(Au, Aw, ..., Az) refer to the sub-

tuple of values <vu, vw, ..., vz> from tj for attributes Au, Aw, ..., Az• Therefore, a tuple is a set of <attribute, value> pairs

2

Characteristics of Relations

24

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> }

2

Page 13: 03_Relational Data Model Concepts

13

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

Characteristics of Relations

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)

3

25

Characteristics of Relations

26

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., Ashley’s telephone number is NULL could mean

• Ashley doesn’t have a phone

• Ashley has a phone but we don’t know the number (perhaps

withheld)

• Ashley may or may not have a phone, but regardless we don’t

have a number for Ashley

3

Page 14: 03_Relational Data Model Concepts

14

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

Characteristics of Relations

27

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

4

Characteristics of Relations

28

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

4

Page 15: 03_Relational Data Model Concepts

15

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

Relational Model Notation

29

• 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

Relational Databases and Relational Database Schemas

30

• 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

Relational database schema S

Page 16: 03_Relational Data Model Concepts

16

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

Relational Databases and Relational Database Schemas

31

• 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

Relational database state

Relational Databases and Relational Database Schemas

32

Page 17: 03_Relational Data Model Concepts

17

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

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

Page 18: 03_Relational Data Model Concepts

18

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

©1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage LearningSlides 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.)

Practice Clicker Question B

• What year are you in?• A: 1

• B: 2

• C: 3

• D: 4

• E: none of the above

35