Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

07.05 division

173 views

Published on

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

07.05 division

  1. 1. Division Division is not essential operation ; just a useful shorthand. Also true of joins, but joins are so common that systems implementjoins specially. Division is NOT implemented in SQL. Not supported as a primitive operator, but useful for manyexpressing queries Precondition: in A/B, the attributes in B must be included in theschema for A. Also, the result has attributes A-B. SALES(supId, prodId); PRODUCTS(prodId); Relations SALES and PRODUCTS must be built using projections. SALES/PRODUCTS: the ids of the suppliers supplying ALLproducts
  2. 2.  The division is a binary operation that is writtenas R ÷ S The result consists of the restrictions of tuples in R tothe attribute names unique to R The header of R but not in the header of S, for which itholds that all their combinations with tuples in S arepresent in R
  3. 3. Student TaskFred Database1Fred Database2Fred Compiler1Eugene Database1Eugene Compiler1Sarah Database1Sarah Database2Completed DBProjectTaskDatabase1Database2Completed÷DBProjectStudentFredSarah
  4. 4. sNo pNos1 p1s1 p2s1 p3s1 p4s2 p1s2 p2s3 p2s4 p2s4 p4pNop2A B1 A/B1sNos1s2s3s4
  5. 5. sNo pNos1 p1s1 p2s1 p3s1 p4s2 p1s2 p2s3 p2s4 p2s4 p4pNop2p4A B2 A/B2sNos1s4
  6. 6. sNo pNos1 p1s1 p2s1 p3s1 p4s2 p1s2 p2s3 p2s4 p2s4 p4pNop1p2p4A B3 A/B3sNos1
  7. 7.  Suppose that employees of the company are assignedto some professional courses; each employee followsseveral courses and each course is taken by severalemployees Information about courses and which employee takeswhich course can be represented by the followingrelations Takes (Emp#, Course#) Courses (Course#, Topic, Weeks)
  8. 8.  Assume that these two relations have the followingcontentEmp# Course#7369 107369 207369 307782 107782 40Course# Topics Weeks20 CAD 510 DB 330 DB 240 OS 4Takes Courses
  9. 9.  Consider the following query: “determine the emp# ofthe employees taking all the courses with topic DB”(Q1) The course# of the courses relevant to the query isobtained through the following expression:R1 = ∏ Course# (σ Topic=“DB”) (Courses))The result of such query is {10, 30}
  10. 10.  The result of query Q1 is represented by all theemployees that appear in the Takes relation with eachof the course numbers retrieved by query R1 The correct result of Q1 is thus {7369} The operation that allows one to execute such query isthe division
  11. 11.  Let R and S be relations; let UR and US be the attribute sets of R and S, respectively, and such that UR US The division operation is denoted asR ÷ Sand is expressed as follows ∏(UR -US) (R) - ∏ (UR -US) ((∏ (UR –US) (R) X S) – R) The expression on the right side of the – signdetermines all tuples of R that are not associated withat least a tuple of S
  12. 12.  Query Q1 is thus expressed as follows:Takes ÷ ∏ Course# (σ Topic=“DB”) (Courses))R = TakesS = ∏ Course# (σ Topic=“DB”) (Courses))S = {10, 30}UR = {Emp#, Course#}Us = {Course#}

×