Professional Documents
Culture Documents
The Language of The Databases
The Language of The Databases
DELETE r
who keeps the relationship, but eliminates all the tuples in it.
The command to modify the structure of a table can be used to add or remove attributes
within an existing r relationship in the database:
where A represents the attribute, and D represents the range of values to be assigned to it.
SQL is a highly performing query language, thanks to the benefit of processing on record
sets. However, it can not provide the necessary procedures to perform a series of activities and
actions, such as creating friendly graphical user interfaces, creating and printing reports,
interacting with other users, transferring data between the database and applications. For this
reason, it is necessary to use a third generation programming language to connect to the database
and perform tasks from the above.
The SQL standard defines the EXEC statement that can be used in such situations:
Provides a set of procedures that allow basic operations to manipulate database data. The
Data Handling Language provides a collection of operators that can be applied to validate
instance data types within the schema and create, modify, or extract such instances. With these
operators, the following operations can be performed:
1) Retrieve database data (main operation).
2) Insert new data into the database.
3) Modify existing data.
4) Delete data from the database.
There are two types of data manipulation languages:
Limits of manipulating procedural data (specific to network and hierarchical models) that allow
the user to tell the system what data is needed and how it can be retrieved. These languages
process the registration information with registration.
Handles of non-procedural data (relational model specific) that allow the user to
communicate to the system what data is needed without specifying how the data is found. These
languages process the information on sets of records and have the following features:
provides greater independence of data;
increase the speed of information processing;
are Fourth Generation Language (4GL).
Examples of such languages belonging to the fourth generation are:
SQL language
QBE language
generators of forms;
reports generators;
graphic generators;
application generators.
V. EXTRACTING INFORMATION FROM DATABASES
The data manipulation language allows extracting data from a database. The basic
structure of an SQL expression consists of using the SELECT, FROM, and WHERE clauses.
SELECT is a clause that uses a list of attributes to be presented to the user and which
corresponds to the relational algebra projection operation.
FROM is a clause that corresponds to the Cartesian product of relational algebra, and in
which the relationships from which the attributes that appear in the SELECT clause are to be
extracted.
WHERE is a clause corresponding to the selection predicate in relational algebra.
Typically a query is in the form of:
where each Ai represents an attribute, each one represents a relation, and P is a predicate.
If the WHERE clause is omitted, the predicate P is True. The list of attributes can be
replaced by a * character to choose them all. Through SQL, the Cartesian product is constructed
based on the specified relationships, a selection can be made using a predicate, after which a
projection can be made on certain attributes. The result of an SQL query is also a relationship,
and by default duplicate records are not removed. Arithmetic operations can also be found in the
selection list.
WHERE clause
Predicates can be of any degree of complexity and may involve:
o logical connections of type "and", "or", or "not";
o arithmetic expressions containing constants or values of tuples;
o the "between" operator used to define variable value ranges.
FROM clause
The FROM clause itself defines a Cartesian product based on relationships that are specified
within it. SQL does not provide the equivalent of the natural junction, but it can be expressed
using a Cartesian product followed by selection and projection operations. The variables, which
in SQL are represented by the relations tuples, are defined in the FROM clause and can be used
in the expressions.
Renaming operation
Renaming is a mechanism used to change the names of relationships or attributes. To do this,
you can use the AS clause that can appear both in the SELECT clause and in the FROM clause
as:
Old_name AS_name
Operations with strings
The most common operations made with strings are those in which Like or Not Like
operators are used to retrieve specified character sets. You can also use a number of other
character functions, such as concatenating, subtracting, determining the length of a character
string, and so on.
Ordering the display of records
SQL allows the user to control the order of the tuples by using the ORDER BY clause. The
sorting operation can be very costly and should only be done in cases where it is necessary.
Duplicated bugs
Formal query languages are based on mathematical relationships. For this reason, duplicate
records are not allowed in the relationships, but since deleting them is extremely expensive, SQL
admits duplicates. If it is desired to delete them, the DISTINCT clause may be used, and if it is
desired to ensure that the duplicate records are not removed, the ALL clause is used.
Operations with crowds
SQL uses the meeting, intersection and difference in this case. The duplication is removed by
the meeting operation, but if not followed, the UNION ALL clause may be used. In the case of
the difference operation, it can be stated that the 1986 SQL standard provided for the MINUS
clause for this operation, while the 1992 standard renamed the clause that is now used as
EXCEPT.
Aggregate functions
SQL can function with groups of tuples using the GROUP BY clause. These attributes are
used to form groups that have the same values, so SQL can determine:
o average value (Avg);
o Minimum value (Min)
o maximum (Max)
o total sum of values (Sum);
o total number of records in the group.
All these functions are called aggregated or totalizing functions. Such functions return a
single value as a result. If both the WHERE clause and the HAVING clause appear in the same
query, the WHERE clause of the WHERE clause is first applied. Those tuples fulfilling the
required condition are entered into groups using the GROUP BY clause. The HAVING clause is
applied to each group that is being formed. Groups fulfilling the condition imposed by the
HAVING clause are used by the SELECT clause to generate the resulting tuples. If there is no
HAVING clause, the tuples fulfilling the condition imposed by the WHERE clause are treated as
if they were a single group.