You are on page 1of 8

THE LANGUAGE OF THE DATABASES

To build a database a user must:


a) Define the database schema;
b) Apply a collection of operators to create, store, extract and modify data.
A common database management system needs to provide a number of tools to ease the
previously specified activities. In this respect, SQL must be the relational standard language of
the database, having the following components:
a) Data Definition Language (DDL) used to define a database schema
b) Data Manipulation Language (DML) that allows the user to manipulate database objects
and their relationships in the context of the database schema.
These languages may differ from one manufacturer to another in the model they use because
of complexity, functionality, and ease of use (user interface). Often, these languages are referred
to as sublimations of data because they do not include constructions for all computational needs
such as those provided by high-level languages. Most database management systems have
incorporated sublimation into a high-level programming language (eg C ++). In this case, high-
level language is called host language.

I. THE LANGUAGE FOR DEFINING DATA


Allows the database administrator or the user to describe and name the entities in the
database as well as the relationships that may exist between the different entities. The data
definition language is a collection of instructions used to describe the data types. The database
administrator must define the structure of the database using these data types. It is used to define
a database schema or to modify an existing one. The result of compiling instructions from the
data definition language is a set of tables stored in special files called system catalogs. The
system catalog contains the meta-data (the data that describes the objects in the database).
Metadata contain definitions of data records and other objects required by the database
management system. The database management system first consults the system catalog to
access the data correctly. Theoretically, there are three data definition languages:
o for the external scheme;
o for the conceptual scheme;
o for the internal scheme.
The data definition language contains commands required for the following operations:
o defining relationship schemes;
o elimination of relations;
o creating indexes;
o modifying schemas.
The data definition language allows you to specify the following information in any
database:
o the schema of each relationship in the database;
o the range of values associated with each attribute;
o integrity constraints;
o the set of indexes that are created for each relationship;
o information on the security of the system and how to access it;
o physical data storage structure of the data.
o
II.DEFINING THE SCHEMA IN SQL
A relationship in SQL is defined by the syntax:
CREATE TABLE r (A1; D1; A2; D2; ...; An; Dn, integrity constraint1 i, ... ,
constraint_inintegrity1 i) where r represents the name of the relationship, Ai represents the name
of an attribute, and Di represents the domain in which it values that attribute. The permitted
integrity constraints are the primary key (Aj1; ... ; Ajm) and the validation rules for the value
range (check (P)).
A primary key must meet two conditions:
o Primary key values must be unique.
o In a primary key there must be zero values.
The SQL-92 standard considers that the occurrence of the "not null" constraint in the
primary key is a redundant fact, but the SQL-89 standard requires explicit definition of this.
Validation check rules prove to be extremely useful in increasing database functionality but are
sometimes costly, as is the case with external key usage.
If you want to remove a relationship from the database, use the following relationship:
DROP TABLE r

which is not the same as:

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:

ALTER TABLE ADD A D

where A represents the attribute, and D represents the range of values to be assigned to it.

ALTER TABLE r DROP A

Where A represents the attribute to be removed from the database.

III.USING SQL QUERIES IN APPLICATIONS

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:

EXEC SQL statement


The allowed SQL statements are: DECLARE CURSOR, OPEN and FETCH that process
the data from the registration database with registration, as well as instructions for modifying,
inserting or deleting the data.
The Dynamic SQL Component allows you to create and use SQL queries to modify while
running applications. Also, SQL-92 standard introduces modules to define procedures in SQL.

IV. THE LANGUAGE OF DATA MANIPULATION

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:

SELECT A1; A2;....;


FROM r1; r2;...; rm
WHERE P

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.

VI. THE CONCEPT OF NULL


Queries that do not know all the values to be displayed cause problems because an
unknown value can not be compared or used as part of an aggregate function. All comparisons
involving unknown values are false by definition. To determine if unknown results are in the set
of results, you can use the NULL keyword to perform such a test. All aggregated functions,
except for the COUNT function, ignore the tuples having unknown values.

Relationships obtained by coupling


The SQL-92 standard states that each coupling operation must have a junction type and a
coupling condition. The types of junctions provided in that standard are the inner junctions, the
left outer junctions, the right outer junctions and the complete outer junctions. The "inside" and
"external" keywords are optional because the junction type can be deduced from the junction
itself. In the SQL-92 standard, two more types of junctions are introduced:
a. Cross junction (an internal junction without coupling condition);
b. junction of junction (a complete outer junction applied to a false coupling condition,
such as for example the situation where the inner junction contains no recording).
The use of a coupling condition is obligatory for external junctions, but is optional for
inner junctions (if omitted, a Cartesian product is obtained).

VII. OTHER SQL FEATURES


SQL is part of the so-called fourth-generation language category because of its power,
concision and low-level procedures. Database products contain a special language that helps
application programmers create templates, user interfaces, and data reports. In the fourth-
generation languages there is no unanimously accepted standard. The SQL-92 standard defines
SQL sessions and environments. The SQL session is a concept related to client / server
technology (connecting, disconnecting, performing or resuming transactions), while the SQL
environment provides each user with an identifier and schema.
As non-procedural language, SQL allows users to specify what to do without showing
how to do it. The request made by a user is transformed by the database management system into
the technical details needed to obtain the data. For this reason, it is said that relational databases
require much less programming effort than any other type of database or file system, which
makes SQL language relatively easy to learn.

You might also like