Page 1 1 Relational Algebra & Calculus Page 2 1 Relational Algebra & Calculus 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports simple, powerful QLs: § Strong formal foundation based on logic. § Allows for much optimization. v 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 data sets. Page 3 1 Relational Algebra & Calculus 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports simple, powerful QLs: § Strong formal foundation based on logic. § Allows for much optimization. v 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 data sets. 3 Formal Relational Query Languages v Two mathematical Query Languages form the basis for “real” languages (e.g. SQL), and for implementation: § Relational Algebra: More operational (procedural), very useful for representing execution plans. § Relational Calculus: Lets users describe what they want, rather than how to compute it: Non-operational, declarative. Page 4 1 Relational Algebra & Calculus 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports simple, powerful QLs: § Strong formal foundation based on logic. § Allows for much optimization. v 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 data sets. 3 Formal Relational Query Languages v Two mathematical Query Languages form the basis for “real” languages (e.g. SQL), and for implementation: § Relational Algebra: More operational (procedural), very useful for representing execution plans. § Relational Calculus: Lets users describe what they want, rather than how to compute it: Non-operational, declarative. 4 Preliminaries v 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. § The schema for the result of a given query is also fixed! - determined by definition of query language constructs. v Positional vs. named-field notation: § Positional notation easier for formal definitions, named-field notation more readable. § Both used in SQL Page 5 1 Relational Algebra & Calculus 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports simple, powerful QLs: § Strong formal foundation based on logic. § Allows for much optimization. v 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 data sets. 3 Formal Relational Query Languages v Two mathematical Query Languages form the basis for “real” languages (e.g. SQL), and for implementation: § Relational Algebra: More operational (procedural), very useful for representing execution plans. § Relational Calculus: Lets users describe what they want, rather than how to compute it: Non-operational, declarative. 4 Preliminaries v 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. § The schema for the result of a given query is also fixed! - determined by definition of query language constructs. v Positional vs. named-field notation: § Positional notation easier for formal definitions, named-field notation more readable. § Both used in SQL 5 Example Instances sid sname rating age 22 dustin 7 45.0 31 lubber 8 55.5 58 rusty 10 35.0 sid sname rating age 28 yuppy 9 35.0 31 lubber 8 55.5 44 guppy 5 35.0 58 rusty 10 35.0 sid bid day 22 101 10/10/96 58 103 11/12/96 R1 S1 S2 v “Sailors” and “Reserves” relations for our examples. v 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.Read More

Offer running on EduRev: __Apply code STAYHOME200__ to get INR 200 off on our premium plan EduRev Infinity!