0% found this document useful (0 votes)
26 views

An Introduction To Relational Database

The document provides an overview of the relational database model. It discusses three key aspects: 1) The structural aspect where data is organized into tables. 2) Integrity constraints that tables must satisfy. 3) Manipulative operators like restrict, project, and join that are used to retrieve and combine data from tables. Examples of each operator are provided on sample department and employee tables. The document also defines relations, relation variables, relation values, base relations, derived relations, and views.

Uploaded by

Myo Thi Ha
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

An Introduction To Relational Database

The document provides an overview of the relational database model. It discusses three key aspects: 1) The structural aspect where data is organized into tables. 2) Integrity constraints that tables must satisfy. 3) Manipulative operators like restrict, project, and join that are used to retrieve and combine data from tables. Examples of each operator are provided on sample department and employee tables. The document also defines relations, relation variables, relation values, base relations, derived relations, and views.

Uploaded by

Myo Thi Ha
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

1

CHAPTER III

AN INTRODUCTION TO RELATIONAL DATABASE

3.1 AN INFORMAL LOOK AT THE RELATIONAL MODEL

Relational System are based on the relational model of data.


1. Structural aspect: The data in the database is perceived by the user as tables, and
nothing but tables.
2. Integrity aspect: Those tables satisfy certain integrity constraints (to be discussed toward
the end of this section);
3. Manipulative aspect: The operators available to the user for manipulating those tables-
e.g., for purposes of data retrieval- are operators that derive tables from tables. Of
those operators, three particularly important ones are restrict, project, and join.

DEPT# DNAME BUDGET


DEPT D1 Marketing 10M
D2 Development 12M
D3 Research 5M

EMP
EMP# ENAME DEPT# BUDGET
E1 Lopez D1 40K
E2 Cheng D1 42K
E3 Finzi D2 30K
E4 Saito D2 35K
Fig. 3.1 The departments and employees database(sample values)

Definitions of those operations are:


 The restrict operation (also known as select) extracts specified rows from a
table.
 The project operation extracts specified columns from a table.
 The join operation joins two tables together on the basis of common values in
a common column.
2

Restrict: Result: DEPT# DNAME BUDGET


D1 Marketing 10M
DEPTs where BUDGET > 8M D2 Development 12M

Project: Result: DEPT# BUDGET


D1 10M
DEPTs over DEPT#, BUDGET D2 12M
D3 5M

Join:
DEPTs and EMPs over DEPT#E4

Result: DEPT# DNAME BUDGET EMP# ENAME SALARY


D1 Marketing 10M E1 Lopez 40K
D1 Marketing 10M E2 Cheng 42K
D2 Development 12M E3 Finzi 30K
D2 Development 12M E4 Saito 35K

Fig. 3.2 Restrict, project and join (examples)

DEPT# DNAME BUDGET EMP# ENAME DEPT# SALARY


D1 Marketing 10M E1 Lopez Di 40K
(column names shown for explicitness) join together to produce the result row

DEPT# DNAME BUDGET EMP# ENAME SALARY


D1 Marketing 10M E1 Lopez 40K

The relational model consists of the following five components;


1. An open-ended collection of scalar types (including in particular the type Boolean or
truth value);
2. A relation type generator and intended interpretation for relations of types
generated thereby;
3. Facilities for defining relation variables of such generated relation types;
4. A relational assignment operation for assigning relation values to such relation
variables;
5. An open-ended collection of generic relational operators for deriving relation values
from other relation values.
3

3.2 RELATIONS AND RELVARS

"Relation" is just a mathematical term for a table- to be precise, a table of a certain


specific kind. Thus, for example, we can say that the departments and employees database of
Fig.3.1 contains two relations.
DEPT and EMP in the database are really relation variables- variables , that is whose
values are relation values(different relation values at different times).
Suppose EMP currently has the value –the relation value, and suppose we delete the row
for saito (employee number E4):

DELETE EMP WHERE EMP# = 'E4' ;

EMP
EMP# NAME DEPT# SALARY
E1 Lopez D1 40k
E2 Chenz D1 42k
E3 Finzi D2 30k

Relation Va1riable

Conceptually, the old relation value of EMP has been replaced by an entirely new
relation value. The old value (with four rows) and the new one (with three) are very similar, but
conceptually they are different values.
Indeed, the delete operation is basically just shorthand for a certain relational assignment
operation.

EMP:= EMP MINUS (EMP WHERE EMP# = 'E4';

Both the original DELETE and the equivalent assignment statement are also basically
shorthand for certain relational assignments.
INSERT, UPDATE
The term relvar as a convenient shorthand for relation variable and relation mean relation
value.

Relation Value(Relation)

 Restrict, project and join (examples) Every relation value has two parts
 The heading is a set of column name: type- name pairs.
 The body is a set of rows that conform to the heading.
4

EMP
EMP#: EMP# ENAME:NAME DEPT:DEPT SALARY
E1 Lopez D1 40k
E2 Chanz D1 42k
E3 Finzi D2 30k
E4 Saito D2 35k

Sample EMP relation value. With column types shown.

 The heading of a given relation can be regarded as a predicate.


 Each row in the body of a relation denotes a certain true proposition, obtained by certain
argument values of the appropriate type or parameters of the predicate.

For example, the predicate looks some thing like this:

Employee
EMP# is named ENAME, works in department DEPT#, and earns salary
SALSARY.

And the corresponding true propositions are:

Employee
E1 is named Lopez, works in department D1, and earns salary 40k.
(obtained by substitution the EMP# value E1, the NAME value Lopez, the DEPT# value
D1, and the MONEY value 40k for the appropriate parameters);

Employee
E2 is named Chenz, works in department D1, and earns salary 42k.
(obtained by substitution the EMP# value E2, the NAME value Chenz, the DEPT# value
D1, and the MONEY value 42k for the appropriate parameters); and so on.

Base Relvars And Views

 The original(given) relvars are called base relvars, and their relation values are called
base relations;
 A relation that is or can be obtained from those base relations by means of some
relational expression is called a derived or derivable relation.
 Base relvars are called real relvars.
 Relational systems obviously have to provide a means for creating the base relvars in the
first place.
5

For example:

CREATE TABLE EMP-----;


However, relational systems usually support another kind of named relvar also, called a view,
whose value at any given time is a derived relation (and so a view can be thought of, loosely,
as a derived relvar).

For example:

CREATE VIEW TOPEMP AS (EMP WHERE SALARY > 33k)


{ EMP#, ENAME, SALARY};

TOPEMP
EMP# ENAME DEPT# SALARY
E1 Lopez D1 42k
E2 Chenz D1 40k
E3 Finzi D2 30k
E4 Saito D2 35k

TOPEMP as a view of EMP (unshaded potions)

 If DEPT and EMP are thought of as real relvars, then TOPEMP might be thought of
as a virtual relvar:- i.e., a relvar that apparently exiats in its own right, but in fact does
not (its value at any given time depends on the value (s) of certain other relvar(s)).
 The base relvar vs. view distinction is frequently characterized thus:
 Base relvars
6

You might also like