Presentation is loading. Please wait.

Presentation is loading. Please wait.

Announcements - Spring 2015 March 2, 2015

Similar presentations


Presentation on theme: "Announcements - Spring 2015 March 2, 2015"— Presentation transcript:

1 Announcements - Spring 2015 March 2, 2015
HW 4 Due 11:59pm, Wednesday, March 4 Review Functional Dependencies/Normalization Semester Project Teams of 3 – 1 team of 4 Phase I – DB Design – Due March 13 11:59 Phase II – App D&D – Due April 20, 11:59 We’ll Discuss Today Upcoming Lectures March 4: Exam Review & XML – Steve March 12: DB Prog/php/REST API – Gino Midterm Exam – Tuesday March 10, ITE138 Questions???

2 Problem th ed Consider the table: Orders (O#,I#,Odate, Cust#, Total_amount, Qty_ordered, Total_price, Discount%) What are the Functional Dependencies?: Is it in 2 NF ? O#  Odate Cust# Total_amt O# I#  Qty_ordered Total_price Discount% No! Odate, Cust#, Total_amt Partially Dependent on only Part of Key O# I# namely O#

3 Problem th ed How do you Fix the Single Orders Table? Is it in 3NF? Yes – No transitive functional dependencies XY and Y Z , with X as the Primary Key, where Y is not a candidate key Create Two Tables Order (O#,Odate, Cust#, Total_amount) OrderedItem (O#,I#, Qty_ordered, Total_price, Discount%)

4 Problem th ed Consider the table: CAR_SALE( Car# , Date_sold, Salesman#, Commision%, Discount_amt) Assumptions Car can be sold by Multiple Salepersons Thus, Primary Key: Car# , Salesman# w/ FDs Car#  Date_sold Car#  Discount_amt Car#  Salesman# Salesman#  Commission% Is it in 2NF? No! Car#  Date_sold and Car#  Discount_amt are not FFD on Primary Key – since Depend on Only Part

5 Problem 15.30 How Do you Convert to 2NF? Recall FDs
Split into Three Tables Car#  Date_sold Car#  Discount_amt Car#  Salesman# Salesman#  Commission% CAR1( Car# , Date_sold, Discount_amt) CAR2( Car# , Salesman#) CAR3(Salesman#, Commision%)

6 Problem th ed Consider the table: TreatPatient (Doctor#, Patient#, Date, Diagnosis, Treat_code, Charge) Assumptions and FDs Patient Treated by Physician on Date with a Diagnosis, Treatment Code, and Charge Every Treatment Code has a Charge {Doctor#, Patient#, Date}{Diagnosis, Treat_code, Charge} {Treat_code}{Charge} Is it in 3NF? No - Convert

7 Problem 15.33 What do you look for? Transitivity What is the Problem?
Charge a non-Key Attribute is Dependent on Treat Code another non-Key Attribute Split into Two Tables FDs Now are Fine TreatPatient (Doctor#, Patient#, Date, Diagnosis, Treat_code) BillingAmount(Treat_code, Charge)

8 Problem 15.35 Given Table Below - What is Candidate Key?
BOOK (Book_Name, Author, Edition, Year) Book_Name, Author, Edition Why? Sometimes Edition Issues Twice in 1 Year What is the main FD? Book_Name, Edition  Year Is it in 2NF? No: Since Year Dependent on only Part of Key Convert: BOOK (Book_Name, Author, Edition) BOOK_YEAR (Book_Name, Edition, Year)

9 Problem 15.35 What are the Multi-Valued Dependencies?
BOOK(Book_Name, Author, Edition) BOOK_YEAR(Book_Name, Edition,Year) What are the Multi-Valued Dependencies? How Do You Separate the Dependencies Book_Name  Author Book_Name  Edition. SPLIT INTO THREE TABLES BOOK (Book_Name, Edition) BOOK_AUTHOR (Book_Name, Edition, Author) BOOK_YEAR (Book_Name, Edition, Year)

10 Announcements - Spring 2015 February 26, 2015
Homework 4: Assigned Today Due – Monday, March 2, 11:59 pm Submit to Homework 4 on HuskyCT Midterm Exam Review – Tuesday March 3 Midterm Exam – Thursday, March 5, 5:10-6:30pm Location – ITE138 Open Book Open Notes Common Schema: Exam Advice Homework 1 and 2 Solutions Posted – will Updated with 3 and 4

11 Homework 4 EER to Relational Conversion See Chapter 9 Class Notes
See Chapter 9 Class Notes

12 EER Diagram

13 Announcements - Spring 2015 February 17, 2015
Homework 3: Assigned Today Due – Monday, February 23, 11:59 pm Submit to Homework 3 on HuskyCT

14 Homework 3 - Four Problems
First two Problems – Write SQL Homework Problem 3.1: 3rd, 4th, and 5th Editions: Problem 8.11; Problem 6.18 from the 6th edition but do this in SQL and NOT relational calculus. Homework Problem 3.2: 3rd, 4th, and 5th Editions: Problem 8.13a, b, and c; Problem 4.10 from the 6th edition. Use MySQL Workbench Load DBs/SQL Queries Homework Problem 3.3: Chinook Schema Homework Problem 3.4: Northwind Schema

15 Homework 3 - Four Problems
Instructions to load DB, generat EER, perform SQL queries For example – the Chinook DB: See various web links: Extract the file: ChinookDatabase1.4_CompleteVersion.zip to get the file: Chinook_MySql.sql

16 Initial MySQL Workbench Screen

17 Instructions – import .sql file

18 Instructions – Query DB

19 Instructions – Query DB

20 Instructions – Generate EER

21 Instructions – Generate EER

22 Instructions – Generate EER

23 Chinook EER

24 Albums and Tracks If you want to see data:
SELECT * FROM CHINOOK.ALBUM; SELECT * FROM CHINOOK.TRACK;

25 Northwind EER

26 SELECT * FROM NORTHWIND.PRODUCTS;

27 Look at 1st Problem Homework 3 7.23 3rd or 6.18 4th to 6th
a. How many copies of the Book titled “The last Tribe” Are owned by the library Branch whose name is “Sharpstown”? What Tables are Needed? Book and Book_Copies to find the number of copies of “The Last Tribe” book Join on BookID Combine the result with the Library_Branch table for the “Sharpstown” Branch Join on BrachID

28 7.23a 3rd/6.18a How many copies of the Book titled “The last Tribe” Are owned by the library Branch whose name is “Sharpstown”? Finding “The Last Tribe” book and its copies at each Bracnh BOOKRES = BOOKCOPIES * (Title=‘The Lost Tribe’ (BOOK))) ) BookId This gives us a result table linked on BookID for ‘The List Tribe” that has rows for each library branch that has that book along with No_of_Copies Finding “Sharpstown” Branch BRANCHRES = BranchName=‘Sharpstown’ (LIBRARY-BRANCH)) This gives us a result table with the BrachID of ‘Sharpstown” Combining the results ANSWER = No_Of_Copies (BRANCHRES * BOOKRES)) BranchId

29 Single Relational Algebra Statement
No_Of_Copies( (BranchName=‘Sharpstown’ (LIBRARY-BRANCH)) * BrachID (BOOKCOPIES *(Title=‘The Lost Tribe’ (BOOK))) ) BookId How do we write the SQL Query? What are Joins? SELECT No_of_Copies FROM LIBRARY-BRANCH, BOOK, BOOKCOPIES WHERE BOOK.TITLE = ‘THE LOST TRIBE’ AND LIBRARY-BRANCH.BRANCHNAME = ‘THE LOST TRIBE’ AND BOOKCOPIES.BOOKID = BOOK.BOOKID AND BOOKCOPIES.BRANCHID = LIBRARYBRANCH.BRANCHID

30 Another HW3 Hint – What about Problem 3.3c?
Find all of print album name and tracks of all of the albums by the composer James Hetfield, grouped by Album What Does Data for Track Look Like? SELECT NAME, COMPOSER FROM CHINOOK.TRACK;

31 Another HW3 Hint – What about Problem 3.3c?
There are other Spellings to Consider: J. Hetfield There are some Hetfields without First Name or Initial What SQL Command is Needed for Searching Composer? LIKE is Used to Compare Partial Strings '%' (or '*') Replaces an Arbitrary # of characters '_' replaces a single arbitrary character SELECT FNAME, LNAME FROM EMPLOYEE WHERE ADDRESS LIKE '%Houston,TX% '

32 Another HW3 Hint – What about Problem 3.4b and c?
Count and print the number of suppliers for each of the eight different categories of food which by name are: Beverages, Condiments, Confections, Dairy Products, Grains/Cereals, Meat/Poultry, Produce, Seafood For each country (ShipCountry in Orders), total the Freight charges. The countries are: France, Germany, Brazil, Belgium, Switzerland, Venezuela, Austria, Mexico, USA, Sweden, Finland, Italy, Spain, UK, Ireland, Portugal, Canada, Denmark, Poland, Norway, Argentina Need to use Both Grouping and Aggregation Operations See Slides 123 and 124 from Chapter 8

33 Announcements - Spring 2015 February 10, 2015
Homework 2: Assigned Today Due – Monday, February 16, 11:59 pm Submit to Homework 2 on HuskyCT Use Slide 7 of this PPT as basis for each problem.

34 Look at 1st Problem Homework 2 7.23 3rd or 6.18 4th to 6th
a. How many copies of the Book titled “The last Tribe” Are owned by the library Branch whose name is “Sharpstown”? What Tables are Needed? Book and Book_Copies to find the number of copies of “The Last Tribe” book Join on BookID Combine the result with the Library_Branch table for the “Sharpstown” Branch Join on BrachID

35 How many copies of the Book titled “The last Tribe” Are owned by the library Branch whose name is “Sharpstown”? Finding “The Last Tribe” book and its copies at each Bracnh BOOKRES = BOOKCOPIES * (Title=‘The Lost Tribe’ (BOOK))) ) BookId This gives us a result table linked on BookID for ‘The List Tribe” that has rows for each library branch that has that book along with No_of_Copies Finding “Sharpstown” Branch BRANCHRES = BranchName=‘Sharpstown’ (LIBRARY-BRANCH)) This gives us a result table with the BrachID of ‘Sharpstown” Combining the results ANSWER = No_Of_Copies (BRANCHRES * BOOKRES)) BranchId

36 BookId BranchId Name: Your name goes here Problem 7.23a or 6.18a
Finding “The Last Tribe” book and its copies at each Bracnh BOOKRES = BOOKCOPIES * (Title=‘The Lost Tribe’ (BOOK))) ) BookId Finding “Sharpstown” Branch BRANCHRES = BranchName=‘Sharpstown’ (LIBRARY-BRANCH)) Combining the results ANSWER = No_Of_Copies (BRANCHRES * BOOKRES)) BranchId

37 Announcements - Spring 2015 February 5, 2015
Homework 1: Due: Saturday, Feb 7, at 11:59pm. zip up the four files LastName_Problem1.1.mwb LastName_Problem1.2.mwb LastName_Problem1.3.docx LastName_Problem1.4.docx into a LastName_FirstName_HMWK1.zip Upload into Husky CT

38 Consider Requirements for Managing Books Across Multiple Branches of Library
Books and Branches have unique identifiers A book has a title, publisher, and pub date Publishers have names and contact info Authors need to be uniquely identified and associated with the books that they have written Borrowers need to be uniquely identified and have unique Library Card numbers and contact info A library has branches each with a unique ID Borrowers take out book loans at a given branch with the data checked out and date due A library keeps track of all of the books including potential multiple copies Design an EER diagram

39 WRITES Author PersonID FirstName LastName Person

40 In Class ER/EER to Relational Conversion

41 What are Steps STEP 1: CONVERT EACH ENTITY CREATE A TABLE
STEP 2: WEAK ENTITIES CREATE TABLE LINK TO STRONG STEP 3: 1-1 RELATIONSHIPS INCLUDE FKEY IN ONE OF TWO STEP 4: 1- MANY INCLUDE REFERNCE FKEY TO MANY SIDE STEP 5: MANY-MANY NEW TABLE STEP 6: MULTI-VALUED STEP 7: N-ARY (3 or MORE) STEP 8: INHERITANCE

42 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

43 Tables for ER Diagram NOTE: For clarity used PNAME, MDNAME, DCNAME, DNAME STEP 1: PATIENT (PNAME, ADDRESS, PHONE#, SSN, ) PHYSICIAN (MDNAME, ADDRESS, PHONE#, DEA#, , SPECIALITY) DRUGCOMPANY (DCNAME, ADDRESS, PHONE#, WEBSITE) DRUG (DNAME, PRICE, EXPIRATION, STATUS) STEP 2: NO WEAK ENTITIES STEP 3: NO 1-1 RELATIONSHIPS STEP 4: 1- MANY – PATIENT & PRIMARY PATIENT HAS 1 PRIMARY PHYSICIAN PHYSICIAN HAS MULTIPLE PATIENTS INCLUDE PNAME KEY INTO PATIENT NO ATTRIBUTES ON REALTION TO ADD: PATIENT (PNAME, ADDRESS, PHONE#, SSN, , MDNAME)

44 Tables for ER Diagram STEP 5: M – N RELATIONSHIPS
PRESCRIBES- BUILD A NEW TABLE WITH KEYS OF PATIENT, PHYSICIAN, and DRUG AND ADD ATTRIBUTES) PRESCRIBES (PNAME, MDNAME, DNAME, REFILLS, DOSAGE, DATE, PATTERN, FILL_REQUREMENT ) PURCHASINGCONTRACT– SIMILAR TO PRESCRIBES PURCHASINGCONTRACT (DCNAME, DNAME, START_DATE, END_DATE) SOLDBY EASIER – NO RELATIONSHIP ATTRIBUTES SOLDBY(DNAME, DCNAME)

45    name address email 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

46 Tables for ER Diagram NOTE: For clarity used PNAME, MDNAME, DCNAME, DNAME STEP 1: PATIENT (PNAME, ADDRESS, PHONE#, SSN, ) PHYSICIAN (MDNAME, ADDRESS, PHONE#, DEA#, , SPECIALITY) DRUGCOMPANY (DCNAME, ADDRESS, PHONE#, WEBSITE) DRUG (DNAME, PRICE, EXPIRATION, STATUS) STEP 2: NO WEAK ENTITIES STEP 3: NO 1-1 RELATIONSHIPS STEP 4: 1- MANY – PATIENT & PRIMARY PATIENT HAS 1 PRIMARY PHYSICIAN PHYSICIAN HAS MULTIPLE PATIENTS INCLUDE PNAME KEY INTO PATIENT NO ATTRIBUTES ON REALTION TO ADD: PATIENT (PNAME, ADDRESS, PHONE#, SSN, , MDNAME)

47 Tables for EER Diagram Inheritance OPTION 1:
PERSON (PNO, PNAME, ADDRESS, PHONE#, ) DRUGPRESCRIBER (PNO, DEA#) PATIENT (PNO, SSN) PHYSCIAN(PNO, DEA#, SPECIAITY) Inheritance OPTION 3: TYPE = PATIENT, PHYSICIAN, PRESCRIBER PERSON (PNO, PNAME, ADDRESS, PHONE#, , TYPE, SSN#, DEA#, SPECIALITY) NO CHANGE IN DRUG and DRUGCOMPANY TABLES NO CHANGE IN RELATIONSHIPS M – N RELATIONSHIPS PRESCRIBES (PNAME, MDNAME, DNAME, REFILLS, DOSAGE, DATE, PATTERN, FILL_REQUREMENT ) PURCHASINGCONTRACT (DCNAME, DNAME, START_DATE, END_DATE) SOLDBY(DNAME, DCNAME)


Download ppt "Announcements - Spring 2015 March 2, 2015"

Similar presentations


Ads by Google