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

Presentation on dbms(relational calculus)

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