Relational Query Languages
Query languages: Allow manipulation and retrieval of data from a database.
 Relational model supports simple, powerful QLs:
• Strong formal foundation based on logic.
• Allows for much optimization.
 Query Languages != programming languages!
• QLs not intended to be used for complex calculations.
• QLs support easy, efficient access to large data sets.
Formal Relational Query Languages
Two mathematical Query Languages form the basis for “real” languages (e.g. SQL), and for implementation:
Relational Algebra: More operational, very useful for
representing execution plans.
Relational Calculus: Lets users describe what they
want, rather than how to compute it. (Nonprocedural,declarative.)
Note: Understanding Algebra & Calculus is key to
understanding SQL, query processing!
Preliminaries
A query is applied to relation instances, and the
result of a query is also a relation instance.
• Schemas of input relations for a query are fixed (but
query will run over any legal instance)
• The schema for the result of a given query is also
fixed. It is determined by the definitions of the query
language constructs.
Relational Algebra: 5 Basic Operations
 Selection ( ): Selects a subset of rows from relation
(horizontal).
 Projection ( ): Retains only wanted columns from relation
(vertical).

Crossproduct ( ): Allows us to combine two relations.
 Setdifference ( — ): Tuples in r1, but not in r2.
 Union ( ): Tuples in r1 or in r2.
Learn Joint Queries in sql
4 years ago
loved the way you explained things. Much better many here
ReplyDeletebba