Querying Relational Databases

Queries directly to the database happens through an application or a website. Questions can be ask to the database and answers received. Another operator may ask another question and s/he would get an answer back. The same questioner or someone else might as to modify the database and they might want to insert new data or update some of the data and the database will notify that "Confirm, changes have been made.".

  • Ad-hoc queries in high-level language.

    • examples:

      • All Data Entries with date > 2013 and modified by Hevok and EVA only.
      • All Research institutes in USA with < 3 research labs on Aging
      • Research labs with highest impact factor over the last 5 years
    • Some easy to pose; some a bit harder

    • Some easy for DBMS to execute efficiently; some harder
    • Easy to pose and easy to execute is not correlated to each other
    • "Query language" is also used to modify data
  • Queries return Relations ("compositional", "closed")

  • Query languages

    • Relational Algebra (formal)
    • SQL (actual/implemented)

Relational databases support ad-hoc queries and and high-level languages. This means it is possible to to pose queries that were not thought in advance. In such, it is not necessary to write long programs for specific queries, rather than the language can be used to pose a query about what is requested.

The languages supported by relational systems are high level, meaning that is is possible to write in a fairly compact fashion rather than complicated queries and it is not necessary to write the algorithms that get the data out of the database.

Arbitrary complicated queries can be written in a few lines of for instance SQL language or a pretty simple expression in relational algebra. Though some queries are easier than other, that is certainly true. Queries can be easy to pose. Some queries are easier for the database system to execute efficiently than others. Interestingly it is not necessary. There two things are not necessary correlated. There are some queries that are easy to pose but had to execute efficiently and some that are vice versa.

The Query languages of a database system is usually used sort of synonymously with the DML (Data Manipulation Language) which usually not only includes querying but also data modifications. In all relational queries, when asking a query over a set of relations, a relation is returned as result.

When the same type of object that is queried is returned, this is known as closure of the language. For example, when run another query, that query could be posed over the answer of the first query and could even be combine that answer with some of the existing relations in the database. This is compositionality, the ability to run a query over th result of the previous query.

There are two query languages. Relational algebra is a formal language, which is just an algebra, but theoretically well-grounded. SQL by contrast is an actual language or an implemented language. This means that is one which is to be run on an actual deployed database Application. The SQL language does has its foundation in relational algebra. That is how the semantics of the SQL language are defined.

In relational algebra the basic operators language are Greek symbols. The corresponding SQL query, is in fact, directly equivalent to the relational algebra query.

queries.jpg/
Edit tutorial

Comment on This Data Unit