1
CS 2550 / Spring 2006 Principles of Database Systems
Alexandros Labrinidis University of Pittsburgh 03 – SQL
Alexandros Labrinidis, Univ. of Pittsburgh
2
CS 2550 / Spring 2006
SQL
SQL = Structured Query Language
since early 1970s
Combination of relational algebra and relational calculus
constructs
More acronyms:
DML: Data Manipulation Language DDL: Data Definition Language Includes view definition, integrity constraints,
authorization control
Alexandros Labrinidis, Univ. of Pittsburgh
3
CS 2550 / Spring 2006
Relation Schema Example
Account (account_number, branch_name, balance)
Branch (branch_name, branch_city, assets)
Customer (customer_name, customer_street, customer_city)
For simplicity assume customer_name unique
Depositor (customer_name, account_number)
Loan (loan_number, branch_name, amount)
Borrower (customer_name, loan_number)
Alexandros Labrinidis, Univ. of Pittsburgh
4
CS 2550 / Spring 2006
Basic Structure
A typical SQL query has the form:
select A1, A2, ..., An RA projection from r1, r2, ..., rm RA cartesian product where P RA selection
Ai represent attributes ri represent relations P is a predicate
Query is equivalent to the relational algebra expression:
∏A1, A2, ..., An (σP (r1 x r2 x ... x rm))
NOTE: SQL results may contain duplicates
The result of an SQL query is a relation.