Presentation on dbms(relational calculus)


Published on

Published in: Education, Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Presentation on dbms(relational calculus)

  2. 2. INTRODUCTION TO RELATIONAL MODEL <ul><ul><li>Invented by E.F. (Ted) Codd </li></ul></ul><ul><ul><li>Based on first-order predicate logic </li></ul></ul><ul><ul><li>Its core idea is to describe a database as a collection of predicates over a finite set of predicate variables, describing constraints on the possible values and combinations of values. </li></ul></ul>TUSHAR GUPTA
  3. 3. THE MODEL <ul><ul><li>Data is represented as mathematical n -ary relations, an n -ary relation being a subset of the Cartesian product of n domains. </li></ul></ul><ul><ul><li>two-valued predicate logic , meaning there are two possible evaluations for each proposition : either true or false. </li></ul></ul><ul><ul><li>Data are operated upon by means of a relational calculus (procedural) or relational algebra (descriptive), these being equivalent in expressive power . </li></ul></ul>TUSHAR GUPTA
  4. 4. THE MODEL <ul><ul><li>The basic relational building block is the domain or data type (or relvar). </li></ul></ul><ul><ul><li>A tuple is an set of attribute values. </li></ul></ul><ul><ul><li>An attribute is an ordered pair of attribute name and type name . </li></ul></ul>TUSHAR GUPTA
  5. 5. SQL AND THE RELATIONAL MODEL <ul><ul><li>Duplicate rows </li></ul></ul><ul><ul><li>Anonymous columns </li></ul></ul><ul><ul><li>Duplicate column names </li></ul></ul><ul><ul><li>Column order significance </li></ul></ul><ul><ul><li>NULL </li></ul></ul>TUSHAR GUPTA
  6. 6. RELATIONAL OPERATIONS <ul><ul><li>Join </li></ul></ul><ul><ul><li>Project - process of eliminating some of the columns </li></ul></ul><ul><ul><li>Restrict - process of eliminating some of the rows </li></ul></ul><ul><ul><li>Union - a way of combining two tables with similar structures </li></ul></ul>TUSHAR GUPTA
  7. 7. RELATIONAL OPERATIONS <ul><ul><li>Difference- lists the rows in one table that are not found in the other </li></ul></ul><ul><ul><li>Intersect - lists the rows found in both tables </li></ul></ul><ul><ul><li>Product - combines each row of one table with each row of the other </li></ul></ul>TUSHAR GUPTA
  8. 8. RELATIONAL CALCULUS <ul><ul><li>Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus (DRC). </li></ul></ul><ul><ul><li>Calculus has variables, constants, comparison ops , logical connectives and quantifiers . </li></ul></ul><ul><ul><ul><li>TRC : Variables range over (i.e., get bound to) tuples . </li></ul></ul></ul><ul><ul><ul><li>DRC : Variables range over domain elements (= field values). </li></ul></ul></ul>TUSHAR GUPTA
  9. 9. RELATIONAL CALCULUS <ul><ul><li>Expressions in the calculus are called formulas . </li></ul></ul><ul><ul><li>An answer tuple is essentially an assignment of constants to variables that make the formula evaluate to true . </li></ul></ul>TUSHAR GUPTA
  10. 10. TUPLE RELATIONAL CALCULUS <ul><ul><li>Query: {T|P(T)} </li></ul></ul><ul><ul><ul><li>T is tuple variable </li></ul></ul></ul><ul><ul><ul><li>P(T) is a formula that describes T </li></ul></ul></ul><ul><ul><li>Result: the set of all tuples t for which P(t) evaluates True. </li></ul></ul><ul><ul><ul><li>Find all sailors with a rating above 7. </li></ul></ul></ul>TUSHAR GUPTA
  11. 11. TRC <ul><ul><li>Atomic formula </li></ul></ul><ul><ul><ul><li>R.a op S.b , op is one of </li></ul></ul></ul><ul><ul><ul><li>R.a op constant </li></ul></ul></ul><ul><ul><li>Formula </li></ul></ul><ul><ul><ul><li>Any atomic formula combined: </li></ul></ul></ul>TUSHAR GUPTA
  12. 12. TRC <ul><ul><li>Example </li></ul></ul><ul><ul><ul><li>Find the names and ages of sailors with a rating above 7 </li></ul></ul></ul><ul><ul><ul><li>Find the names of sailors who have reserved all boats </li></ul></ul></ul>TUSHAR GUPTA
  13. 13. DOMAIN RELATIONAL CALCULUS <ul><ul><li>Query has the form: </li></ul></ul><ul><ul><li>Answer includes all tuples that make the formula be true . </li></ul></ul><ul><ul><li>Atomic formula: </li></ul></ul><ul><ul><ul><li>, Where Rname is relation specified or could be as X op Y, or X op constant </li></ul></ul></ul><ul><ul><ul><li>op is one of </li></ul></ul></ul>TUSHAR GUPTA
  14. 14. DRC <ul><ul><li>Formula: </li></ul></ul><ul><ul><ul><li>an atomic formula, or </li></ul></ul></ul><ul><ul><ul><li>,               where p and q are formulas, or </li></ul></ul></ul><ul><ul><ul><li>,                 where variable X is free in p(X) </li></ul></ul></ul>TUSHAR GUPTA
  15. 15. DRC <ul><ul><li>Examples </li></ul></ul><ul><ul><li>Find all sailors with a rating above 7 </li></ul></ul><ul><ul><li>Find sailors rated > 7 who’ve reserved boat #103 </li></ul></ul>TUSHAR GUPTA
  16. 16. UNSAFE QUERIES, EXPRESSIVE POWER <ul><ul><li>It is possible to write syntactically correct calculus queries that have an infinite number of answers! Such queries are called unsafe . </li></ul></ul><ul><li>Eg: </li></ul><ul><ul><li>It is known that every query that can be expressed in relational algebra can be expressed as a safe query in DRC / TRC; the converse is also true. </li></ul></ul>TUSHAR GUPTA
  17. 17. LIMITATIONS OF THE RELATIONAL ALGEBRA / CALCULUS <ul><li>Can not do: </li></ul><ul><ul><li>Aggregate operations </li></ul></ul><ul><ul><li>Recursive queries </li></ul></ul><ul><ul><li>Complex (non-tabular) structures </li></ul></ul><ul><ul><li>Most of these are expressible in SQL, OQL, XQuery – using other special operators </li></ul></ul>TUSHAR GUPTA