Presentation is loading. Please wait.

Presentation is loading. Please wait.

Homework 1 Solution.

Similar presentations


Presentation on theme: "Homework 1 Solution."— Presentation transcript:

1 Homework 1 Solution

2 EER and EER for Pharmacy
For ER 1-1, 1-m, m-n, and m-1 relationships Attribute definitions on entities - more than described. Primary MD as relationship Missing RX number from Prescription Entity For EER Use of extended ER constructs for inheritance Who can prescribe has changed Relationship between Prescriber and Patient Limit “Who” can prescribe to one of the options (use disjoint)

3 ER for Problem 1.1 name Phone# name email N 1 SSN Physician Patient
Primary Physician specialty Patient address address DEA# refills N dosage Prescribes date N Fill requirement pattern Sold By expiration price Purchasing Contract Drug name status start_date end_date

4 EER for Problem 1.2    DEA# N 1 SSN Physician Patient refills N
Person Drug Prescriber DEA# N 1 SSN Primary Physician Patient specialty refills N dosage Prescribes date N Fill requirement pattern Sold By expiration price Purchasing Contract Drug name status start_date end_date

5 EER for Problem 1.2 Notice Movement of Common Attributes to Person and DEA number to Presriber “Person” is a parent of both Patient and Physician and Physician also a Sub-entity of Drug Prescriber DEA# name phone address Drug Prescriber Person Physician Physician

6 Problem 3.19

7 Problem 3.23 a. Entity types: BANK, ACCOUNT, CUSTOMER, LOAN
b. Weak entity type: BANK-BRANCH. Partial key: BranchNo. Identifying relationship: BRANCHES. c. The partial key BranchNo in BANK-BRANCH specifies that the same BranchNo value may occur under different BANKs. The identifying relationship BRANCHES specifies that BranchNo values are uniquely assigned for those BANK-BRANCH entities that are related to the same BANK entity. Hence, the combination of BANK Code and BranchNo together constitute a full identifier for a BANK-BRANCH.

8 Problem 3.23 d. Relationship Types: BRANCHES, ACCTS, LOANS, A-C, L-C. The (min, max) constraints are shown below.

9 Problem 3.23 e. The requirements may be stated as follows: Each BANK has a unique Code, as well as a Name and Address. Each BANK is related to one or more BANK-BRANCHes, and the BranchNo is unique among each set of BANK-BRANCHes that are related to the same BANK. Each BANK-BRANCH has an Address. Each BANK-BRANCH has zero or more LOANS and zero or more ACCTS. Each ACCOUNT has an AcctNo (unique), Balance, and Type and is related to exactly one BANK-BRANCH and to at least one CUSTOMER. Each LOAN has a LoanNo (unique), Amount, and Type and is related to exactly one BANK-BRANCH and to at least one CUSTOMER. Each CUSTOMER has an SSN (unique), Name, Phone, and Address, and is related to zero or more ACCOUNTs and to zero or more LOANs.

10 Problem 7.23a 3rd/6.18a 4th & 5th How many copies of the book titled The Lost Tribe are owned by the library branch whose name is ‘Sharpstown’? No_Of_Copies( (BranchName=‘Sharpstown’ (LIBRARY-BRANCH)) * BrachID (BOOKCOPIES *(Title=‘The Lost Tribe’ (BOOK))) ) BookId

11 Homework 2 Solution – 40 pt total
For Problem /6.18 – a, b, c, and d No points for 7.23a/6.18a – solution posted on web 6 pts each for b and c 8 pts for d – see point breakdown on slide 2 Note – show using P(rojection), S(elect), *(join) Or the equivalent Greek letters For Problem /6.20 – a, b, and c 5pts a, 3 pts b, 4 pts c For Problem /6.22 – a, b, e, and f only 2 pts per table for each a, b, e, and f

12 Problem 7.23 3rd/6.18 4th & 5th – a to d
a. P No_Of_Copies ( ( s BranchName='Sharpstown' (LIBRARY-BRANCH) ) * (BOOKCOPIES * ( s Title='The Lost Tribe’ (BOOK) ) ) ) b. P BranchID, No_Of_Copies ( ( s Title='The Lost Tribe' (BOOK)) * BOOKCOPIES * LIBRARY_BRANCH ) No_Of_Copies( (BranchName=‘Sharpstown’ (LIBRARY-BRANCH)) * BrachID (BOOKCOPIES *(Title=‘The Lost Tribe’ (BOOK))) ) BookId BranchName, No_Of_Copies( (Title=‘The Lost Tribe’ (BOOK)) * BOOKCOPIES * LIBRARY_BRANCH) BookId BrachId 2 pts each BookID and BranchId joins 1pt select, 1pt project

13 Problem 7.23 3rd/6.18 4th & 5th – a to d
c. NO_CHECKOUT_B = P CardNo (BORROWER) - P CardNo (BOOK_LOANS) RESULT = P Name (BORROWER * NO_CHECKOUT_B) d. S = P BranchId ( s BranchName='Sharpstown' (LIBRARY-BRANCH) ) B_FROM_S = P BookId,CardNo ( ( s DueDate='today' (BOOKLOANS) ) * S ) RESULT = P Title,Name,Address ( BOOK * BORROWER * B_FROM_S ) NO_CHECKOUT_B =CardNo(BORROWER) - CardNo(BOOK_LOANS) ANSWER = Name(BORROWER * NO_CHECKOUT_B) 2 pts BORROWER – BOOK LOANS; 1pt for Project CardNo 2 pts BORROWER/NO_CHECKOUT_B join, 1 pt Project Name S =BranchID( BranchName=‘Sharpstwon’ (LIBRARY-BRANCH)) BranchId B_FROM_S = BookID, CardNo ( ( DueDate=‘Today’ (BOOKLOANS)) * S ) ANSWER = Title, Name, Address ( BOOK * BORROWER * B_FROM_S ) BookId CardNo 2 pts each BookID, CardNo, and BranchId joins ½ pt per each select or project

14 Problem 7.25 3rd/6.20 4th & 5th – a to c
Schema is: SALESPERSON(Ssn, Name, Start_year, Dept_no) TRIP(Ssn, From_city, To_city, Departure_date, Return_date, Trip_id) EXPENSE(Trip_id, Account#, Amount) The schema of this question has the following two foreign keys: 1. the attribute SSN of relation TRIP that references relation SALESPERSON, and 2. the attribute Trip_ID of relation EXPENSE that references relation TRIP. In addition, the attributes Dept_No of relation SALESPERSON and Account# of relation EXPENSE are foreign keys referencing other relations of the database not mentioned in the question. 1.5 pt select, 1.5 pt project, 2 point join 1.5 pt select, 1.5 pt project 2 pt join, 1 select, 1 project a. COSTLY_TRIPS = ( SUM_Amount>2000(Trip_ID, SUM(Amount) (EXPENSE)) RESULT = TRIP * Trip_ID (COSTLY_TRIPS) b. RESULT = SSN (  To_City=‘Honolulu’ (TRIP)) c. RESULT = SUM(Amount) ( SSN=‘ ’ (TRIP) * EXPENSE )

15 Problem 7.27 3rd/6.22 4th & 5th – a to g


Download ppt "Homework 1 Solution."

Similar presentations


Ads by Google