Database Sql

Only available on StudyMode
  • Download(s) : 83
  • Published : December 16, 2012
Open Document
Text Preview
Lecture-13
Structured Query Language (SQL)

Introduction
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.

Basic Structure
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
where P
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]

Select Clause
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
select branch-name
from Loan
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
from Loan
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....
tracking img