Database Reference
In-Depth Information
Retrieving data from a relational database through the use of relational algebra involves issuing relational
algebra commands to operate on existing tables to form a new table containing the desired information.
Sometimes you might need to execute a series of commands to obtain the desired result.
59
NOTE
Unlike QBE, relational algebra is not used in current DBMS systems. Its importance is the theoretical base it furnishes to the
relational model and the benchmark it provides. Other approaches to querying relational databases are judged by this
benchmark.
NOTE
There is no “standard” method for representing relational algebra commands; this section illustrates one possible approach.
What is important is not the particular way the commands are represented, but the results they provide.
As you will notice in the following examples, each command ends with a GIVING clause, followed by a
table name. This clause requests that the result of the command be placed in a temporary table with the
specified name.
SELECT
In relational algebra, the SELECT command takes a horizontal subset of a table; that is, it retrieves certain
rows from an existing table (based on some user-specified criteria) and saves them as a new table. The
SELECT command includes the word WHERE followed by a condition. The rows retrieved are the rows in
which the condition is satisfied.
EXAMPLE 19
List all information about customer 282 from the Customer table.
SELECT Customer WHERE CustomerNum=282
GIVING Answer
This command creates a new table named Answer that contains only one row in which the customer number
is 282, because that is the only row in which the condition is true. All the columns from the Customer table
are included in the new Answer table.
EXAMPLE 20
List all information from the Customer table about all customers with credit limits of $7,500.
SELECT Customer WHERE CreditLimit=7500
GIVING Answer
This command creates a new table named Answer that contains all the columns from the Customer table, but
only those rows in which the credit limit is $7,500.
PROJECT
In relational algebra, the PROJECT command takes a vertical subset of a table; that is, it causes only certain
columns to be included in the new table. The PROJECT command includes the word OVER followed by a list
of the columns to be included.
Search WWH ::




Custom Search