SQL (Structured Query Language) [22] has evolved as a high level, robust and compact DDL (Data Definition Language) and DML (Data Manipulation Language, for DDL and DML see Chapter 3). It was formerly known as SEQUEL which was developed by IBM in San Jose, CA, originally for use in the experimental database system called System R [22]. The language is now used by majority of database systems.
SQL standards are stated faster than implementations. There are three major dialects standardized by ANSI: SQL, SQL2 (also known as SQL-92) and SQL3 (known as SQL-99) [7]. In most cases a RDBMS (Relational Database Management System) complies with some subset of the standard. On the other hand, different ``out-of-standard'' features are often incorporated in RDMBS, extending - in some, vendor specific, way - their functionality.
The DML part of SQL is divided into the following categories [22,7]:
The most significant is Selection. There are three keywords: SELECT, FROM, WHERE, which comply with the following syntax:
SELECT L FROM R WHERE C;
The above statement corresponds to the relational algebra expression (see Section 3.2):
Extending the selection query, functionality of intersection, difference, and union can be achieved [22].
In SQL one query can be used as a part of another query. Such a query is called a subquery. Subqueries can have subqueries and so on, down to as many levels as necessary. There are three ways subqueries can be used:
In SQL, there is an ability to partition the tuples of a relation into ``groups'', based on the values of tuples in one or more attributes. Then other columns of the relation may be aggregated by applying ``aggregation'' operators to those columns. The aggregation is performed separately for each group. This functionality is provided by GROUP BY clause and aggregation operators in SELECT clauses.
In addition there is a way to filter out the tuples which match certain values of the aggregation operators. It is provided by HAVING clause. There are five basic aggregation operators: SUM, AVG, MIN, MAX, and COUNT, which calculate the sum, average, minimum value, maximum value and number of tuples in the group.
There is an important difference between WHERE and HAVING clauses. WHERE applies to the tuples which are being selected, while HAVING applies to groups of tuples.
There are also other queries that do not return values but modify the contents of the database. They fall into three categories:
Removing a tuple from some given relation is provided by DELETE clause, which is defined as:
Finally, updating some tuples is provided by UPDATE, which has the following syntax:
As it was mentioned at the beginning of this section, SQL provides also the DDL functionality. Thus, this portion of SQL involves describing the structure of information in the database. In order to declare a relation schema, which is usually called a table in terms of SQL, the principal atomic data types should be known. There are basic six categories [22]:
Modifying a relation schema is significantly more often then removing it.
The modification means adding or removing some attributes.
It is provided by ALTER TABLE statement which is defined as follows:
There is another class of SQL relations - they are called views.
A regular relation actually exists in the database, while a view is defined by an expression much like a query.
Views in turn, can be queried as regular relations, so as they existed physically, and in some cases they can even be modified.
The simplest form of a view definition is:
The syntax and functionality described above does not fully cover SQL. Some more details on this subject may be found in [7,22,6,23].
To summarize SQL covers the core Relational Model operations (see Chapter 3). All these operations require that the number of relations is stated a priori. So it is not possible to parameterize it. In general, problems which involve recursive processing are not addressable.
Moreover, the model indicates that all the data is atomic. It does not allow to introduce more complex data structures, which limits possible data processing capabilities2.1.
Igor Wojnicki 2005-11-07