1 / 10

Chapter 2: Relational Model

Chapter 2: Relational Model. Set Difference Operation – Example. Relations r , s :. A. B. A. B.   . 1 2 1.  . 2 3. s. r. r – s :. A. B.  . 1 1. Set Difference Operation. Notation r – s Defined as: r – s = { t | t  r and t  s }

spike
Download Presentation

Chapter 2: Relational Model

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. Chapter 2: Relational Model

  2. Set Difference Operation – Example • Relations r, s: A B A B    1 2 1   2 3 s r • r – s: A B   1 1

  3. Set Difference Operation • Notation r – s • Defined as: r – s = {t | t rand t  s} • Set differences must be taken between compatible relations. • r and s must have the same arity • attribute domains of r and s must be compatible

  4. Example Find the names of all customers who have an account but no loan from the bank. customer_name (depositor) - customer_name (borrower) Depositor Borrower

  5. Cartesian-Product Operation – Example • Relations r, s: A B C D E   1 2     10 10 20 10 a a b b r s • r xs: A B C D E         1 1 1 1 2 2 2 2         10 10 20 10 10 10 20 10 a a b b a a b b

  6. Cartesian-Product Operation • Notation r x s • Defined as: r x s = {t q | t  r and q  s} • Assume that attributes of r(R) and s(S) are disjoint. (That is, R  S = ). • If attributes of r(R) and s(S) are not disjoint, then renaming must be used.

  7. Composition of Operations • Can build expressions using multiple operations • Example: A=C(r x s) • r x s • A=C(r x s) A B C D E         1 1 1 1 2 2 2 2         10 10 20 10 10 10 20 10 a a b b a a b b A B C D E       10 10 20 a a b 1 2 2

  8. Banking Example branch (branch_name, branch_city, assets) customer (customer_name, customer_street, customer_city) account (account_number, branch_name, balance) loan (loan_number, branch_name, amount) depositor (customer_name, account_number) borrower(customer_name, loan_number)

  9. Example • Find the names of all customers who have a loan at the Mirpurbranch. customer_name (branch_name=“Mirpur” (borrower.loan_number = loan.loan_number(borrower x loan))) • Find the names of all customers who have a loan at the Mirpurbranch but do not have an account at any branch of the bank. customer_name (branch_name = “Mirpur” (borrower.loan_number = loan.loan_number(borrower x loan))) – customer_name(depositor)

  10. Examples • Find out the customer names who live in Khulna city customer_name (customer_city=“khulna”(customer)) • Find out the customer names who have an account but do not have a loan at any branch of the bank. customer_name (depositor) – customer_name(borrower)

More Related