First page Back Continue Last page Graphics
Types of query languages
Procedural:
- The user specifies which operations to apply on the database in order to produce the answer to a question. (looks like programming)
Declarative:
- The user specifies which data are needed to answer the question but not how to obtain these data. (looks like logic formulas)
Notes:
There are two ways in which you can ask questions to a database:
You can tell the database what to do in order to answer the question. This is in fact a form of programming. A database system is like a computer, with a set of instructions you can use in a program. The instructions are of a higher level than with languages such as Pascal or Java, but they are programming instructions. We can ask a database something like “take the table with the account information; select all the rows or tuples with customer name 'Jones' and then print the value of the balance attribute”. We will study a specific procedural query language: the relational algebra. This will give us a good understanding of the fundamental operations a database system can perform.
You can also specify the answer to your question, and let the database system figure out how to calculate the result. The specification looks like a logic formula. We can ask a database something like: “print the balance of the accounts of customers with anme 'Jones'”. The difference is not yet very clear from this example, but when we use the formal query languages and when we ask much more complicated questions the difference will become very clear. We will study two of these declarative languages: the tuple calculus and SQL.
The declarative query languages work because it is possible to write a procedural query for every query they can express. The converse is also true: every query the database system can answer through its (procedural) operations can be expressed in the declarative languages.