中文网站
  Advanced Search
Read the latest Blogs from IT professionals in the field. Read and write community created documents. Need IT help? Ask our staff. Connect with your peers. Check our Tech Shop for posters, books and software tools. Home

4.2 Database Systems: Basic Structure

1. Basic structure of an SQL expression consists of select, from and where clauses.

  • select clause lists attributes to be copied - corresponds to relational algebra project.
  • from clause corresponds to Cartesian product - lists relations to be used.
  • where clause corresponds to selection predicate in relational algebra.

2. Typical query has the form
select A1,A2, ....,An
from r1, r2, ...., rm
where P

where each Ai represents an attribute, each ri a relation, and P is a predicate.

3. This is equivalent to the relational algebra expression

â…¡A1,A2,....;An(∑P (r1 × r2 ×....×rm))

  • If the where clause is omitted, the predicate P is true.
  • The list of attributes can be replaced with a * to select all.
  • SQL forms the Cartesian product of the relations named, performs a selection using the predicate, then
    projects the result onto the attributes named.
  • The result of an SQL query is a relation.
  • SQL may internally convert into more effcient  expressions.