The document discusses the relational model for databases. The relational model represents data as mathematical n-ary relations and uses relational algebra or relational calculus to perform operations. Relational calculus comes in two flavors: tuple relational calculus (TRC) and domain relational calculus (DRC). TRC uses tuple variables while DRC uses domain element variables. Expressions in relational calculus are called formulas and queries return tuples that make the formula evaluate to true.
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