# I d i d course id takes course id dept name comp sci

• Notes
• 8
• 100% (1) 1 out of 1 people found this document helpful

This preview shows pages 3–6. Sign up to view the full content.

I D ( I D , course id ( takes ) ÷ course id ( dept name = ’Comp. Sci’ ( course )) b. The required expression is as follows: r I D , course id ( takes )

This preview has intentionally blurred sections. Sign up to view the full version.

4 Chapter 6 Formal Relational Query Languages s course id ( dept name = ’Comp. Sci’ ( course )) I D ( takes ) I D (( I D ( takes ) × s ) r ) In general, let r ( R ) and s ( S ) be given, with S R . Then we can ex- press the division operation using basic relational algebra operations as follows: r ÷ s = R S ( r ) R S (( R S ( r ) × s ) R S , S ( r )) To see that this expression is true, we observe that R S ( r ) gives us all tuples t that satisfy the first condition of the definition of division. The expression on the right side of the set difference operator R S (( R S ( r ) × s ) R S , S ( r )) serves to eliminate those tuples that fail to satisfy the second condition of the definition of division. Let us see how it does so. Consider R S ( r ) × s . This relation is on schema R , and pairs every tuple in R S ( r ) with every tuple in s . The expression R S , S ( r ) merely reorders the attributes of r . Thus, ( R S ( r ) × s ) R S , S ( r ) gives us those pairs of tuples from R S ( r ) and s that do not appear in r . If a tuple t j is in R S (( R S ( r ) × s ) R S , S ( r )) then there is some tuple t s in s that does not combine with tuple t j to form a tuple in r . Thus, t j holds a value for attributes R S that does not appear in r ÷ s . It is these values that we eliminate from R S ( r ). 6.5 Let the following relation schemas be given: R = ( A , B , C ) S = ( D , E , F ) Let relations r ( R ) and s ( S ) be given. Give an expression in the tuple rela- tional calculus that is equivalent to each of the following: a. A ( r ) b. B = 17 ( r ) c. r × s d. A , F ( C = D ( r × s )) Answer: a. { t | ∃ q r ( q [ A ] = t [ A ]) } b. { t | t r t [ B ] = 17 } c. { t | ∃ p r q s ( t [ A ] = p [ A ] t [ B ] = p [ B ] t [ C ] = p [ C ] t [ D ] = q [ D ] t [ E ] = q [ E ] t [ F ] = q [ F ]) }
Practice Exercises 5 d. { t | ∃ p r q s ( t [ A ] = p [ A ] t [ F ] = q [ F ] p [ C ] = q [ D ] } 6.6 Let R = ( A , B , C ), and let r 1 and r 2 both be relations on schema R . Give an expression in the domain relational calculus that is equivalent to each of the following: a. A ( r 1 ) b. B = 17 ( r 1 ) c. r 1 r 2 d. r 1 r 2 e. r 1 r 2 f. A , B ( r 1 ) B , C ( r 2 ) Answer: a. { < t > | ∃ p , q ( < t , p , q > r 1 ) } b. { < a , b , c > | < a , b , c > r 1 b = 17 } c. { < a , b , c > | < a , b , c > r 1 < a , b , c > r 2 } d. { < a , b , c > | < a , b , c > r 1 < a , b , c > r 2 } e. { < a , b , c > | < a , b , c > r 1 < a , b , c > r 2 } f. { < a , b , c > | ∃ p , q ( < a , b , p > r 1 < q , b , c > r 2 ) } 6.7 Let R = ( A , B ) and S = ( A , C ), and let r ( R ) and s ( S ) be relations. Write expressions in relational algebra for each of the following queries: a. { < a > | ∃ b ( < a , b > r b = 7) } b. { < a , b , c > | < a , b > r < a , c > s } c. { < a > | ∃ c ( < a , c > s ∧ ∃ b 1 , b 2 ( < a , b 1 > r < c , b 2 > r b 1 > b 2 )) } Answer: a.

This preview has intentionally blurred sections. Sign up to view the full version.

This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern