Professional Documents
Culture Documents
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 expected to be Turing complete.
QLs not intended to be used for complex calculations.
QLs support easy, efficient access to large data sets.
Two mathematical Query Languages form the basis for
real languages (e.g. SQL), and for implementation:
Relational Algebra: More operational (procedural), very useful
for representing execution plans.
Relational Calculus: Describes what users want, rather than
how to compute it: Non-operational, declarative.
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.
The schema for the result of a given query is also fixed! -
determined by definition of query language constructs.
A relation schema can be thought of as the basic
information describing a table or relation.
This includes a set of column names, the data types
associated with each column, and the name
associated with the entire table. For example, a
relation schema for the relation called Students could
be expressed using the followingrepresentation:
Students(sid: string, name: string, login: string,age:
integer, gpa: real)
A relational database schema is a collection of relation
schemas, describing one or more relations.
Student_Detail
STUDENT Student.Std = Subject.Class SUBJECT
Student_detail
SID Name Std Class Subject
101 Alex 10 10 Math
101 Alex 10 10 English
102 Maria 11 11 Music
102 Maria 11 11 Sports
Natural Join: Equijoin on all common fields.
Courses HoD
Dept CID Course Head
CS CS01 Database Alex
ME ME01 Mechanics Maya
EE EE01 Electronics Mira
Theta Join, Equijoin, and Natural Join are
called inner joins. An inner join includes
only those tuples with matching attributes
and the rest are discarded in the resulting
relation. Therefore, we need to use outer
joins to include all the tuples from the
participating relations in the resulting
relation. There are three kinds of outer joins
left outer join, right outer join, and full
outer join.
All the tuples from the Left relation, R,
are included in the resulting relation. If
there are tuples in R without any
matching tuple in the Right relation S,
then the S-attributes of the resulting
relation are made NULL.
Right
Left
A B
A B
100 Alex
100 Database
102 Maya
101 Mechanics
102 Electronics 104 Mira
Courses HoD
A B C D
100 Database 100 Alex
101 Mechanics --- ---
102 Electronics 102 Maya
All the tuples from the Right relation, S, are
included in the resulting relation. If there
are tuples in S without any matching tuple
in R, then the R-attributes of resulting
relation are made NULL.
Courses HoD
A B C D
100 Database 100 Alex
102 Electronics 102 Maya
--- --- 104 Mira
Full Outer Join: ( R S)
Courses HoD
A B C D
100 Database 100 Alex
101 Mechanics --- ---
102 Electronics 102 Maya
--- --- 104 Mira
SELECT * from class, cross JOIN class_info;