Top Banner
Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall
29

Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Jan 04, 2016

Download

Documents

Lindsay May
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: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Chapter 8Foundations of Relational

Implementation

David M. Kroenke

Database Processing

© 2000 Prentice Hall

Page 2: Chapter 8 Foundations 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

Page 3: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Occurrence of a relationPATIENT(Name, DateOfBirth, Gender,

AccountNumber, Physician)

Page 194Figure 8-1 © 2000 Prentice Hall

Page 4: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Chapter 8

© 2000 Prentice Hall

Relational Schema

“The relation structure plus constraints on allowable data values”

Page 194

Page 5: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

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

Page 6: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

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

Page 7: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Chapter 8

© 2000 Prentice Hall

Data Definition Language

“The language used to describe the database structure”– tables– columns– indexes– constraints– security

Page 196

Page 8: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Chapter 8

© 2000 Prentice Hall

Relational Data Manipulation Language

• Relational Algebra• Relational Calculus• Transform-Oriented Languages• Query-by-Example; Query-by-Form

Page 198

Page 9: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

DML Interfaces

• Forms

• Query/Update Language InterfaceSELECT Name, AgeFROM PATIENTWHERE Physician = ‘Levy’

Page 200

Figure 8-8

© 2000 Prentice Hall

Page 10: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Chapter 8

© 2000 Prentice Hall

DML Interfaces

• Stored Procedure InterfaceDO BILLING FOR BDATE = ‘9/15/1999’

• Application Program InterfaceCOBOLBASICPerlC++

Page 201

Page 11: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Relation Definitions

Page 204Figure 8-11a © 2000 Prentice Hall

Page 12: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Attribute Domains

Page 204Figure 8-11b © 2000 Prentice Hall

Page 13: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Domain Definitions

Page 204Figure 8-11c © 2000 Prentice Hall

Page 14: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Example Data

Figure 8-12 © 2000 Prentice Hall

Page 15: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Union“adding tuples from one relation to

those of a second” A+B

Page 205Figure 8-12 © 2000 Prentice Hall

Page 16: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 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

Page 17: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Intersection

“contains tuples in both the first and second”

Page 206Figure 8-14 © 2000 Prentice Hall

Page 18: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Product

“selects specified attributes (columns) from a relation”

Page 206Figure 8-17 © 2000 Prentice Hall

Page 19: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Selection

“selects tuples (rows) from a relation”

Page 206Figure 8-18 © 2000 Prentice Hall

Page 20: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 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

Page 21: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Equijoin, Natural, Left Outer

Page 209Figure 8-19 © 2000 Prentice Hall

Page 22: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Summary of Relational Algebra Operators

Page 209Figure 8-20 © 2000 Prentice Hall

Page 23: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Chapter 8

© 2000 Prentice Hall

Expressing Queries

1.What are the names of all students?

STUDENT [Name]

Page 210

Page 24: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

Chapter 8

© 2000 Prentice Hall

Expressing Queries

2. What are the student numbers of all students enrolled in a class?

ENROLLMENT [StudentNumber]

Page 211

Page 25: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

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

Page 26: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

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

Page 27: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

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

Page 28: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

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

Page 29: Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.

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