Documente Academic
Documente Profesional
Documente Cultură
Domains, Relations & Base RelVars (Ch. 5 Overview) Relational Algebra & Calculus,, & SQL (Ch. 6,7) Preview Design Issues & Integrity Constraints (Ch.8) A Design Review
Ch. 5?
Each attribute implies a domain (data type, set of values) Types do not imply physical representation (encap)
But at least one possible physical representation is suggested
Specific data types are orthogonal to the relational model. Scalar types have visible components (non-scalars dont). The relational model is strongly typed. Some operators ( selector = < > := CAST AS )
Type Checking
J.CITY = P.CITY JNAME | | PNAME QTY * 100 QTY + 100 STATUS = 5 J.CITY < S.CITY COLOR = P.CITY J.CITY = P.CITY | | burg
Relational Algebra
Restrict (Select) -- subset of tuples Project -- subset of columns Product -- all possible combinations of two tuples
A B X Y AX AY BX BY
B1 C1 B2 C2 B3 C3
A1 B1 C1 A2 B1 C1 A3 B2 C2
David Maier / Judy Cushing
Other Joins Theta Join -- join two relations but not on the equality operation ((S RENAME CITY AS SCITY) TIMES (P RENAME CITY AS PCITY) ) WHERE SCITY > PCITY Semi Join -- (natural) join two relations, but return only attributes of the first ((S SEMIJOIN (SP WHERE P# = # (P2))
(inv#
(inv#
ext)
(inv#
ext)
Division
Given 2 unary and 1 binary relation -find tuples in the (first) unary relation matched in the binary relation -w/ tuples in the other unary relation
A B C
A A A B C
X Y Z X Y
X Z
Division
phone_bk(person Randall Ross Ricard Randall Ross Rivers Ross Ricard Rivers ext) 2116 2116 2116 2218 2218 2218 3972 3972 3972
s(person)
(ext)
2116 3972
Ross Ricard
* q
Retrieval Update Integrity constraints Derived relvars (views) Stability requirements (concurrency control) Security constraints (scope of authorization) Transformation rules -> OPTIMIZATION ((SP JOIN S) WHERE P# = P# (P2)) {SNAME} ((SP WHERE P# = P# (P2)) JOIN S) {SNAME}
10
Miscellaneous
Relational Comparisons
= equals /= not equals <= subset of (IN) < proper subset of >= superset > proper superset IS_EMPTY GROUP, UNGROUP
11
Relational Calculus
The algebra - a language to describe how to construct a new relation. The calculus - a language to write a definition of that new relation.
FORALL PX (PX.COLOR = COLOR (Red))
EXISTS SPX (SX.S# = SX.S# AND SPX.P# = P# (P2)
12
6.13
J JX SELECT * FROM J ( SPJ WHERE J# = J# (J1) ) {S#} SPJX.S# WHERE SPJX.J# = J# (J1) SELECT DISTINCT SPJ.S# FROM SPJ WHERE SPJ.J# = J1
6.15 Get supplier numbers for suppliers who supply project J1.
6.18 Get supplier-number/part-number/project-number triples such that supplier part and project are all colocated).
(S JOIN P JOIN J) {S#, P#, J#} (SX.S#, PX.P#, JX.J# ) WHERE
SX.CITY = PX.CITY AND PX.CITY = JX.CITY AND JX.CITY = SX.CITY
13
Integrity Preview!
An attribute value must match its type. A primary key must be unique. A tuples foreign key must be of the same type as its matching primary key. To create a record with a given foreign key, a record in the corresponding table must have that value as its primary key. Many to many relationships cannot be modeled (directly). Find examples to support these in SPJ!
Relational Algebra, Calculus & SQL David Maier / Judy Cushing
14
Study Questions Which of the relational algebra, tuple calculus and domain calculus is SQL based on?
15
16