Lecture
The manipulation part of the QUEL language is a pure implementation of relational calculus of tuples. This means that the operators specify the conditions imposed on the tuples with which it is necessary to take appropriate actions.
The core set of data manipulation statements includes the RETRIVE (select), APPEND (add), REPLACE (replace) and DELETE (delete) statements. Before executing any of these operators, it is necessary to determine the variables of the tuples used in them, associating them with the corresponding relations by executing the RANGE operator:
RANGE OF variable-list IS relation-name
Let us demonstrate the basic properties of QUEL operators with examples. We will use the database of STUDENTS and GROUPS:
RANGE OF S IS STUDENTS RANGE OF G IS GROUPS
Example 1. Select the names of students whose supervisor is Ivanov.
RETRIEVE (S.STUD__NAME) WHERE (S.GROUP_NOMER = G.GROUPNOMER AND G.KURAT_IMA = "IVANOV")
Example 2. Enter in relation to FAILING student ID numbers and the names of underperforming students.
RETRIEVE INTO FAILURES (S. STUD_NUMER, S. STUD_IMA) WHERE (S.STUD_USP = "NO")
Example 3. Print the names of students who receive a scholarship below the average.
RETRIEVE (S.STUD__NAME) WHERE (S.STUD_STIP <AVG (S.Stud_STIP))
As with SQL, the aggregate functions COUNT, SUM, MAX, MIN and AVG are supported.
Example 4. To include 310 students Petrov in the group.
APPEND TO STUDENTS (STUD_IMA = "PETROV" ....)
Example 5. Increase the scholarship by 1.5 times to all successful students.
REPLACE S (STUD_STIP BY STUD_STIP * 1.5) WHERE (S.STUD_USP = "YES")
Example 6. Remove from the list of groups all groups in which no student enrolls.
DELETE G WHERE (G.GROUP_SIZE = 0)
In addition to data manipulation operators, the QUEL language contains operators for creating and destroying relationships:
CREATE relation_name (attribute_name IS attribute_type, ...) DESTROY name_relationship
as well as two operators for changing the structures of stored data:
MODIFY relation_name TO structure_memory ON (key 1, key 2, ...) and INDEX ON relation_name IS index_name (key1, key2, ...)
The MODIFY operator modifies the structure of the stored relation in accordance with the memory_structure parameter and a given set of key attributes. The INDEX operator creates a separate index structure for the given fields of a given relation. The created indexes are used by the system to optimize the execution of data manipulation statements. The consistency of the contents of relations and indexes is maintained by the system automatically.
The QUEL language also contains operators for defining integrity constraints, representations and access restrictions. We will dwell on them a little later.
In the form in which we briefly described it, the QUEL language is intended for interactive work with Ingres databases. For programming application information systems that must interact with databases, the EQUEL programming language was developed, which is essentially an extension of the C programming language by embedding the QUEL language operators into it. The EQUEL language is defined as follows:
An example of a program in the EQUEL language, issuing a group number by student's name:
main () { ## char stud_name [20]; ## int group_number; while (READ (stud_name_) { ## RANGE OF S IS STUDENTS ## RETRIEVE (group_number = G.GROUP.NUMBER) ## WHERE (S.STUD_NAME = stud_name) { PRINT ("The group number of 'stud_name' is 'group_number'); } } }
The program in the EQUEL language is processed by a special preprocessor, which turns it into a regular C program containing calls to Ingres with the transfer as parameters of texts of operators of the QUEL language. We have already discussed the following scheme.
Comments
To leave a comment
IBM System R — реляционная СУБД
Terms: IBM System R — реляционная СУБД