|
relational algebra: resulttable = ra (source table(s))- definition: the algebra of tables: similar to the algebra of scalars, sets, and vectors
- primary operations: selection, projection, and join
- selection: only those rows in source that meet specified value condition(s) survive in the result
- projection: only specified columns in source survive in result
- z=join (x,y): two source tables joined at the hip (side by side) using a common column foreign key to align the rows of y to the corresponding row of x. degree of result is sum of degree(x)=degree(y)-1. not commutative. cardinality of z = cardinality of x.
other useful operations: multiplication and division- multiplication z=x*y: like join but without alignment of rows. every row of y is attached to each row of x. cardinality of z = product of cardinalities of x and y. degree of z = sum of degrees of x and y.
- division z=x/y: those rows in x that match every row in y survive into z. the opposite of multiplication. x*y/x = y and x*y/y=x. very useful for queries where "every occurence" is used as a criterion.
elementary operations: addition, subtraction, and intersection- addition z1=x+y: union. put x on top of y. columns must line up and be of the same domain. degree of z = degree of x = degree of y and cardinality of z = sum of the cardinalities of x and y
- intersection: z2=x&y: rows that are common to x and y make it to z. degree: z=x=y, cardinality: z less than x or y
- subtraction: z=x-y: rows that are not common to x and y make it to z. degree: z=x=y, cardinality: z less than x or y
- relationship between addition, intersection, and subtraction: z1-z2=x-y
relational calculus- a generic and mathematical non procedural query language
- uses relational algebra to extract desired result tables from source tables
- basis for sql, qbe, and other query systems for rdb
sql and qbe- sql: an implementation of relational calculus
|