Chapter 8Foundations of Relational
Implementation
David M. Kroenke
Database Processing
© 2000 Prentice Hall
Chapter 8
© 2000 Prentice Hall
Review of Terminology
Relation “two-dimensional table”• entries are single value• attributes (columns) contain same type of
data• each attribute has a domain (allowed values)• no two rows are identical, order is unimportant• tuple (rows)
Page 193
Occurrence of a relationPATIENT(Name, DateOfBirth, Gender,
AccountNumber, Physician)
Page 194Figure 8-1 © 2000 Prentice Hall
Chapter 8
© 2000 Prentice Hall
Relational Schema
“The relation structure plus constraints on allowable data values”
Page 194
Chapter 8
© 2000 Prentice Hall
Key
“Group of one or more attributes that uniquely identifies a tuple in a relation”– logical– physical (index)
Page 194
Chapter 8
© 2000 Prentice Hall
Implementing a Relational Database
1. Define the database structure to the DBMS
2. Allocate media space3. Create the database data
Page 195
Chapter 8
© 2000 Prentice Hall
Data Definition Language
“The language used to describe the database structure”– tables– columns– indexes– constraints– security
Page 196
Chapter 8
© 2000 Prentice Hall
Relational Data Manipulation Language
• Relational Algebra• Relational Calculus• Transform-Oriented Languages• Query-by-Example; Query-by-Form
Page 198
DML Interfaces
• Forms
• Query/Update Language InterfaceSELECT Name, AgeFROM PATIENTWHERE Physician = ‘Levy’
Page 200
Figure 8-8
© 2000 Prentice Hall
Chapter 8
© 2000 Prentice Hall
DML Interfaces
• Stored Procedure InterfaceDO BILLING FOR BDATE = ‘9/15/1999’
• Application Program InterfaceCOBOLBASICPerlC++
Page 201
Relation Definitions
Page 204Figure 8-11a © 2000 Prentice Hall
Attribute Domains
Page 204Figure 8-11b © 2000 Prentice Hall
Domain Definitions
Page 204Figure 8-11c © 2000 Prentice Hall
Example Data
Figure 8-12 © 2000 Prentice Hall
Union“adding tuples from one relation to
those of a second” A+B
Page 205Figure 8-12 © 2000 Prentice Hall
Difference
“adding tuples that occur in the first relation but not the second” A-B
Page 206Figure 8-13 © 2000 Prentice Hall
Intersection
“contains tuples in both the first and second”
Page 206Figure 8-14 © 2000 Prentice Hall
Product
“selects specified attributes (columns) from a relation”
Page 206Figure 8-17 © 2000 Prentice Hall
Selection
“selects tuples (rows) from a relation”
Page 206Figure 8-18 © 2000 Prentice Hall
Chapter 8
© 2000 Prentice Hall
Join
“combination of the product, selection, and (possibly) projection operations”– equijoin– natural join– left outer join
Page 207
Equijoin, Natural, Left Outer
Page 209Figure 8-19 © 2000 Prentice Hall
Summary of Relational Algebra Operators
Page 209Figure 8-20 © 2000 Prentice Hall
Chapter 8
© 2000 Prentice Hall
Expressing Queries
1.What are the names of all students?
STUDENT [Name]
Page 210
Chapter 8
© 2000 Prentice Hall
Expressing Queries
2. What are the student numbers of all students enrolled in a class?
ENROLLMENT [StudentNumber]
Page 211
Chapter 8
© 2000 Prentice Hall
Expressing Queries
3. What are the student numbers of all students not enrolled in a class?
STUDENT [SID] - ENROLLMENT [StudentNumber]
Page 211
Chapter 8
© 2000 Prentice Hall
Expressing Queries
4. What are the numbers of students enrolled in the class ‘BD445’?ENROLLMENT WHERE ClassName = ‘BD445’[StudentNumber]
Page 211
Chapter 8
© 2000 Prentice Hall
Expressing Queries
5. What are the names of the students enrolled in class ‘BD445’?STUDENT JOIN (SID = StudentNumber) ENROLLMENT WHERE ClassName = ‘BD445’[STUDENT.Name]
Page 211
Chapter 8
© 2000 Prentice Hall
Expressing Queries
6. What are the names and meeting times of ‘PARKS’ classes?STUDENT WHERE Name = ‘PARKS’ JOIN (SID=StudentNumber) ENROLLMENT JOIN (ClassName = Name) CLASS [CLASS.Name, Time]
Page 212
Chapter 8
© 2000 Prentice Hall
Expressing Queries
7. What are the grade levels and meeting rooms of all students, including students not enrolled in a class?STUDENT LEFT OUTER JOIN (SID = StudentNumber) ENROLLMENT JOIN (ClassName = Name) CLASS [GradeLevel, Room]
Page 212
Top Related