Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.
-
Upload
kerry-anthony -
Category
Documents
-
view
217 -
download
2
Transcript of Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.
![Page 1: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/1.jpg)
Announcements
• Reading for Wednesday – 4.6
• Homework 3 – Due 10/1
![Page 2: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/2.jpg)
The Relational Model
Lecture 7
![Page 3: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/3.jpg)
Advantages of Relational Model• Based on mathematical notion of relation• Can use power of mathematical abstraction• Can develop body of results using theorem and proof method of
mathematics – results then apply to many different applications• Can use expressive, exact mathematical notation• Theory provides tools for improving design• Basic structure is simple, easy to understand• Separates logical from physical level• Data operations easy to express, using a few powerful
commands• Operations do not require user to know storage structures used
![Page 4: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/4.jpg)
Data Structures
• Relations are represented physically as tables• Table
• Rows
• Column
• Domains
![Page 5: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/5.jpg)
Properties of Tables
• Each cell• Each column
• Values in a column all come from the same domain
• Each tuple
• Order of tuples is immaterial
![Page 6: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/6.jpg)
Example of Relational Model
• Student table tells facts about students
• Faculty table shows facts about faculty
• Class table shows facts about classes, including what faculty member teaches each
• Enroll table relates students to classes
![Page 7: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/7.jpg)
Mathematical Relations
• Cartesian product
Let D1 = { +, - } Let D2 = {1,2,3} Calculate the Cartesian product
![Page 8: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/8.jpg)
Mathematical Relations
• Relation
• Example
![Page 9: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/9.jpg)
Describing Relations
• Give rules for selection of the tuples that will be part of the relation
![Page 10: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/10.jpg)
Three sets
• Could form Cartesian product of 3 sets; relation is any subset of the ordered triples so formed
• A relation where the third element is the sum of the first two
![Page 11: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/11.jpg)
n-tuples
• Could extend to n sets
![Page 12: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/12.jpg)
Database Relations
• Relation schema, R,
• Relation, r,
![Page 13: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/13.jpg)
Database Relations
• r is a set of n-tuples
(A1:d1, A2:d2, …, An:dn) such that d1є D1, d2 є D2 , …, dn є Dn
![Page 14: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/14.jpg)
Database Relations
• In a table to represent the relation, list the Ai as column headings, and let the (d1, d2, …dn) become the n-tuples, the rows of the table
![Page 15: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/15.jpg)
Properties of Relations
• Degree:–
• Cardinality:–
• Keys• Integrity constraints
![Page 16: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/16.jpg)
Relation Keys
•
• Superkey:
• Candidate key:
![Page 17: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/17.jpg)
Relation Keys
• Primary key:
• Cannot verify a key by looking at an instance; need to consider semantic information to ensure uniqueness
• Foreign key
![Page 18: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/18.jpg)
Integrity Constraints
• Integrity:
•
•
![Page 19: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/19.jpg)
Types of constraints
• Domain constraint:
• Entity integrity:
• Referential integrity:
• General constraints or business rules:
![Page 20: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/20.jpg)
Representing Relational Database Schemas
• Can have any number of relation schemas• For each relation schema list name of relation
followed by list of attributes in parentheses• Underline primary key in each relation schema• Indicate foreign keys (We use italics – arrows are
best)• Database schema actually includes domains, views,
character sets, constraints, stored procedures, authorizations, etc.
![Page 21: Announcements Reading for Wednesday –4.6 Homework 3 – Due 10/1.](https://reader034.fdocuments.us/reader034/viewer/2022051415/56649f485503460f94c6a4e6/html5/thumbnails/21.jpg)
University database schema
Student (stuId, lastName, firstName, major, credits)
Class (classNumber, facId, schedule, room)
Faculty (facId, name, department, rank)
Enroll(stuId,classNumber,grade)