tailieunhanh - Lecture Fundamentals of database systems: Chapter 6 - Emasri, Navathe
In this chapter we discuss the two formal languages for the relational model: the relational algebra and the relational calculus. The main contents in this chapter include: Example database application (COMPANY), overview of the QBE language (appendix D),. Inviting you to refer. | SET DIFFERENCE also called MINUS or EXCEPT is denoted by - The result of R - S is a relation that includes all tuples that are in R but not in S The attribute names in the result will be the same as the attribute names in R The two operand relations R and S must be type compatible Copyright 2007 Ramez Elmasri and Shamkant B. Navathe lide 6- 3 Notice that both union and intersection are commutative operations that is R o S S o R and R n S S n R Both union and intersection can be treated as n-ary operations applicable to any number of relations as both are associative operations that is R o S o T R o S o T R n S n T R n S n T The minus operation is not commutative that is in general R-S S-R Copyright 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6-4 CARTESIAN or CROSS PRODUCT Operation This operation is used to combine tuples from two relations in a combinatorial fashion. Denoted by R A1 A2 . . . An x S B1 B2 . . . Bm Result is a relation Q with degree n m attributes Q A1 A2____An B1 B2___Bm in that order. The resulting relation state has one tuple for each combination of tuples one from R and one from S. Hence if R has nR tuples denoted as R nR and S has nS tuples then R x S will have nR nS tuples. The two operands do NOT have to be type compatible Generally CROSS PRODUCT is not a meaningful operation Can become meaningful when followed by other operations Example not meaningful FEMALE_EMPS a seX .f. EMPLOYEE EMPNAMES . fnamel name ssn FEMALE_EMPS EMP_DEPENDENTS EMPNAMES x DEPENDENT EMP_DEPENDENTS will contain every combination of EMPNAMES and DEPENDENT whether or not they are actually related Copyright 2007 Ramez Elmasri and Shamkant B. Navathe lide 6 Copyright 2007 Ramez Elmasri and Shamkant B. Navathe lide 6- 6 1 To keep only combinations where the DEPENDENT is related to the EMPLOYEE we add a SELECT operation as follows Example meaningful FEMALE_EMPS a SEX F EMPLOYEE EMPNAMES fnamelName ssn FEMALE_EMPS EMP_DEPENDENTS EMPNAMES x DEPENDENT ACTUAL_DEPS a ssn .
đang nạp các trang xem trước