{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

L04 - Relational Query Languages Relational Algebra...

This preview shows pages 1–8. Sign up to view the full content.

Relational Query Languages Relational Algebra

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS174A: Algebra 2 Relational Query Languages ± Query languages: Allow manipulation and retrieval of data 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, persistent data sets
CS174A: Algebra 3 Formal Relational Query Languages ( Understanding Algebra & Calculus is key to understanding SQL, query processing! Two mathematical query languages form the basis for “real” languages (e.g. SQL), and for implementation: X Relational Algebra : More operational , very useful for representing execution plans Y Relational Calculus : Let users describe what they want, rather than how to compute it ( Non-operational , declarative )

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS174A: Algebra 4 Preliminaries ± 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 (but query will run regardless of instance!) – The schema for the result of a given query is also fixed! Determined by definition of query language constructs ± Positional vs. named-field notation: – Positional notation easier for formal definitions, named-field notation more readable – Both used in SQL
CS174A: Algebra 5 Example Instances ± Sailors and Reserves relations for our examples ± We’ll use positional or named field notation, assume that names of fields in query results are ‘inherited’ from names of fields in query input relations 55.5 8 lubber 31 35.0 9 yuppy 28 35.0 10 rusty 58 35.0 5 guppy 44 age rating sname sid S2 45.0 7 dustin 22 35.0 10 rusty 58 55.5 8 lubber 31 age rating sname sid S1 10/10/96 101 22 11/12/96 103 58 day bid sid R1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS174A: Algebra 6 Relational Algebra ± Basic operations: Selection ( σ ) Selects a subset of rows from relation Projection ( π ) Deletes unwanted columns from relation Cross - product ( × ) Allows us to combine two relations Set-difference ( ) Tuples in reln. 1, but not in reln. 2 Union ( ) Tuples in reln. 1 and in reln. 2 ± Additional operations: – Intersection, join , division, renaming: Not essential, but (very!) useful ± Since each operation returns a relation, operations can be composed ! (Algebra is “closed”)
CS174A: Algebra 7 Projection ± Deletes attributes that are not in projection list ± Schema of result contains exactly the fields in the projection list, with the same names that they had in the (only) input relation ± Projection operator has to eliminate

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 29

L04 - Relational Query Languages Relational Algebra...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online