Structured Query Language (SQL)
Commercial database systems use more user friendly language to specify the queries.
SQL is the most influential commercially marketed product language.
Other commercially used languages are QBE, Quel, and Datalog.
The basic structure of an SQL consists of three clauses: select, from and where.
select: it corresponds to the projection operation of relational algebra. Used to list the attributes desired in the result.
from: corresponds to the Cartesian product operation of relational algebra. Used to list the relations to be scanned in the evaluation of the expression
where: corresponds to the selection predicate of the relational algebra. It consists of a predicate involving attributes of the relations that appear in the from clause.
A typical SQL query has the form:
select A1, A2,…, An
from r1, r2,…, rm
Ai represents an attribute
rj represents a relation
P is a predicate
It is equivalent to following relational algebra expression:
"Π" _("A" _"1" "," "A" _"2" ",…" 〖",A" 〗_"n" ) " (" "σ" _"P" " (" "r" _"1" "× " "r" _"2" " ×…×" "r" _"m" "))"
[Note: The words marked in dark in this text work as keywords in SQL language. For example “select”, “from” and “where” in the above paragraph are shown in bold font to indicate that they are keywords]
Let us see some simple queries and use of select clause to express them in SQL.
Find the names of all branches in the Loan relation
By default the select clause includes duplicate values. If we want to force the elimination of duplicates the distinct keyword is used as follows: select distinct branch-name
The all key word can be used to specify explicitly that duplicates are not removed. Even if we not use all it means the same so we don’t require all to use in select clause....