Вы находитесь на странице: 1из 2

UMBC CMSC 461 Spring '99 CSEE | 461 | 461 S'99 | lectures | news | Oracle Help | help

Basic Structure
A relational database is a collection of tables. Each table has its own unique name.

The basic structure of an SQL expression consists of three clauses:

The select clause which corresponds to the projection operation. It is the list of
attributes that will appear in the resulting table.
The from clause which corresponds to the Cartesian-product operation. It is the list
of tables that will be joined in the resulting table.
The where clause which corresponds to the selection operation. It is the expression
that controls the which rows appear in the resulting table.

A typical SQL query has the form of:

select A1, A2, ..., An


from r1, r2, ..., rn,
where P

The query is the equivalent to the relational algebra expression

p A1, A2, ..., An ( sP ( r1 C r2 C ... C rn ) )

The select Clause

Formal query languages are based on the mathematical notion of a relation being a set.
Duplicate tuples never appear in relations. In practice, duplicate elimination is relatively
time consuming. SQL allows duplicates in relations as well as the results of SQL
expressions.

In those cases where we want to force the elimination of duplicates, we insert the
keyword distinct after select. The default is to retain duplicates. This can be explicitly
required with the keyword all.

The asterisk symbol "*" can be used in place of listing all the attributes.

The clause can also contain arithmetic expressions involving the operators +, -, *, and /.

A dot notation is used when explicitly identifying the table that the attribute comes
from: borrower.loan-number
The from Clause

The from clause defines a Cartesian product of the tables in the clause.

The where Clause

SQL uses and, or and not (not symbols) and the comparison operators <, <=, >, >=, = , and
<>. Also available is between:

where amount between 90000 and 100000

Additional, not between can be used.

The rename Operation

SQL uses the as clause:

old_name as new_name

You can do pattern matching on strings, using like and special characters:

% which matching any substring>/li>


_ which matches any single character
escape which allows you override another character:
like "ab\%cd%" escape "\" which matches any strong that starts with
"ab\cd"

Ordering the Display of Tuples

SQL uses the order by clause to control the order of the display of rows, either
ascending (asc) or descending (desc):

order by amount desc

Sorting a large number of tuples may be costly and its use should be limited.

CSEE | 461 | 461 S'99 | lectures | news | help

Tuesday, 08-Jun-1999 11:59:49 EDT

Вам также может понравиться