an introduction to relational databases prof. yin-fu huang csie, nyust chapter 3

15
An Introduction to An Introduction to Relational Databases Relational Databases Prof. Yin-Fu Huang Prof. Yin-Fu Huang CSIE, NYUST CSIE, NYUST Chapter 3 Chapter 3

Upload: silvester-sharp

Post on 02-Jan-2016

224 views

Category:

Documents


0 download

TRANSCRIPT

An Introduction to An Introduction to Relational DatabasesRelational Databases

Prof. Yin-Fu HuangProf. Yin-Fu Huang

CSIE, NYUST CSIE, NYUST

Chapter 3Chapter 3

Advanced Database System Yin-Fu Huang

3.23.2 An Informal Look at the Relational ModelAn Informal Look at the Relational Model

Structural aspect Integrity aspect Manipulative aspect Example (See Fig. 3.1 & 3.2)

Primary keyForeign key

Advanced Database System Yin-Fu Huang

Points from Fig. 3.2:

a. the closure property of

relational systems

b. set-at-a-time

Example (Fig. 3.2)Example (Fig. 3.2)

Advanced Database System Yin-Fu Huang

Points from Fig. 3.1:

a. Tables are the logical

structure, not the

physical structure.

b. The entire information

content of the database

is represented in one

and only one way,

namely as explicit values.

Example (Fig. 3.1)Example (Fig. 3.1)

Advanced Database System Yin-Fu Huang

3.33.3 Relations and RelvarsRelations and Relvars

Relation ? a mathematical term for a table⇒(set theory and predicate logic)

Relation model E. F. Codd (1969-1970)⇒ Delete Emp Where Emp#=‘E4’

(See Fig. 3.3)

A relation variable vs. a relation per se

Advanced Database System Yin-Fu Huang

3.43.4 What Relations MeanWhat Relations Mean

Two parts: the heading & the body

(See Fig. 3.4)

Thinking about relations:

a. predicate

b. true proposition

Advanced Database System Yin-Fu Huang

3.53.5 OptimizationOptimization

Relational languages are often said to be nonprocedural, on the

grounds that users specify what, not how.

Procedurality and nonprocedurality are not absolute.

Optimizer: automatic navigation (See Fig. 3.5)

⇒ an efficient way

Example: Result:=(Emp Where Emp#=‘E4’) {Salary};

a. a physical sequential scan of relvar Emp

b. an index on the Emp#

Advanced Database System Yin-Fu Huang

Automatic vs. manual navigation (Fig. 3.5)Automatic vs. manual navigation (Fig. 3.5)

Advanced Database System Yin-Fu Huang

3.53.5 Optimization (Cont.)Optimization (Cont.)

The considerations:

a. Which relvars are referenced in the request

b. How big those relvars currently are

c. What indexes exist

d. How selective those indexes are

e. How the data is physically clustered on the disk

f. What relational operations are involved

Automatic navigation data independence⇒

Advanced Database System Yin-Fu Huang

3.63.6 The CatalogThe Catalog

Users can interrogate the catalog in exactly the same way they

interrogate their own data. Example (See Fig. 3.6)

(Column Where Tabname=‘Dept’) {Colname}

Advanced Database System Yin-Fu Huang

Base relvars vs. derived relvars A view can be thought of, loosely, as a derived relvar. Example: Create View TopEmp As

(Emp Where Salary > 33K) {Emp#, Ename, Salary};

The view defining expression is not evaluated but is merely

“remembered” by the system in some way. a virtual relvar⇒ A window into the base relvar Any changes: view ⇔ base relvars

Example: (TopEmp Where Salary < 42K) {Emp#, Salary}

(Emp Where Salary > 33K And Salary < 42K) {Emp#, Salary}

3.73.7 Base Relvars and ViewsBase Relvars and Views

Advanced Database System Yin-Fu Huang

3.83.8 TransactionsTransactions

A transaction is a logical unit of work.

Operations: Begin Transaction, Commit, Rollback

Points arising:

a. atomic

b. durable

c. isolated

d. serializable

Advanced Database System Yin-Fu Huang

3.93.9 The Suppliers and Parts DatabaseThe Suppliers and Parts Database

Example (See Fig. 3.8 & 3.9) Entity and Relationship (a special case of an entity)

Advanced Database System Yin-Fu Huang

The suppliers and parts database (Fig. 3.9)The suppliers and parts database (Fig. 3.9)

Advanced Database System Yin-Fu Huang

The End.