1 / 21

Session 3

Session 3. Welcome : To session 3-the second learning sequence “ Relational algebra “ Recap : In the previous learning sequences, we discussed the relational model. Present learning : We shall explore the following topics: - Relational algebra.

jonah-hill
Download Presentation

Session 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Session 3 Welcome: To session 3-the second learning sequence “ Relational algebra “ Recap : In the previous learning sequences, we discussed the relational model. Present learning: We shall explore the following topics: - Relational algebra. - Some operators.

  2. Relational Algebra

  3. Query Languages • Language in which user requests information from the database. • Categories of languages • procedural • non-procedural • “Pure” languages: • Relational Algebra • Tuple Relational Calculus • Domain Relational Calculus • Pure languages form underlying basis of query languages that people use.

  4. Relational Algebra • Procedural language • Four basic operators • select • project • union • Intersection • The operators take one or more relations as inputs and give a new relation as a result.

  5. Select Operation Notation: p(r) p is called the selection predicate Defined as: p(r) = {t | t  rand p(t)} Where p is a formula in propositional calculus consisting of terms connected by :  (and),  (or),  (not)Each term is one of: <attribute> op <attribute> or <constant> where op is one of: =, , >, . <.  Example of selection:branch-name=“Perryridge” (account)

  6. Select Operation – Example Account

  7. Select Operation – Example The result is the relation: 7

  8. Select Operation – Example Balance >“700” (account) 8

  9. Project Operation Notation:A1, A2, …, Ak (r) where A1, A2 are attribute names and r is a relation name. The result is defined as the relation of k columns obtained by erasing the columns that are not listed Duplicate rows removed from result, since relations are sets

  10. Project Operation E.g. To eliminate the branch-name attribute of accountaccount-number, balance (account) The result relation is:

  11. Project Operation 11

  12. Union Operation • Notation: r s • Defined as: r s = {t | t  r or t  s} • For r s to be valid. 1. r,s must have the same arity (same number of attributes) 2. The attribute domains must be compatible (e.g., 2nd column of r deals with the same type of values as does the 2nd column of s)

  13. Union Operation E.g. to find all customers with either an account or a loancustomer-name (depositor)  customer-name (borrower) depositor borrower

  14. Union Operation • customer-name (depositor) customer-name (borrower)

  15. Union Operation • The result relation is:

  16. Intersection Operation • Notation: r s • Defined as: • rs ={ t | trandts } • Assume: • r, s have the same arity • attributes of r and s are compatible • Note: rs = r - (r - s)

  17. Intersection Operation E.g. to find all customers with an account and a loancustomer-name (depositor)  customer-name (borrower) depositor borrower

  18. Intersection Operation • customer-name (depositor) customer-name (borrower)

  19. Intersection Operation The result relation is:

  20. Relational Algebra Summary: In this learning sequence, we discussed Four basic operators of the topic relational algebra.

  21. END

More Related