ann.1 cse4701 announcements - spring 2015 march 2, 2015 hw 4 due 11:59pm, wednesday, march 4 ...
TRANSCRIPT
ANN.1
CSE4701
Announcements - Spring 2015March 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???
ANN.2
CSE4701
Problem 15.29 6th 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#
ANN.3
CSE4701
Problem 15.29 6th ed
How do you Fix the Single Orders Table?
Is it in 3NF? Yes – No transitive functional
dependencies XY 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%)
ANN.4
CSE4701
Problem 15.30 6th 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
ANN.5
CSE4701
Problem 15.30
How Do you Convert to 2NF? Recall FDs
Split into Three Tables
CAR1( Car# , Date_sold, Discount_amt)CAR2( Car# , Salesman#)CAR3(Salesman#, Commision%)
Car# Date_soldCar# Discount_amtCar# Salesman# Salesman# Commission%
ANN.6
CSE4701
Problem 15.33 6th 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
ANN.7
CSE4701
Problem 15.33
What do you look for? Transitivity What is the Problem?
TreatPatient (Doctor#, Patient#, Date, Diagnosis, Treat_code)
BillingAmount(Treat_code, Charge)
Charge a non-Key Attribute is Dependent on Treat Code another non-Key Attribute
Split into Two Tables FDs Now are Fine
ANN.8
CSE4701
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)
ANN.9
CSE4701
Problem 15.35
What are the Multi-Valued Dependencies?
How Do You Separate the Dependencies
BOOK(Book_Name, Author, Edition)BOOK_YEAR(Book_Name, Edition,Year)
Book_Name AuthorBook_Name Edition.
SPLIT INTO THREE TABLES
BOOK (Book_Name, Edition)BOOK_AUTHOR (Book_Name, Edition, Author)BOOK_YEAR (Book_Name, Edition, Year)
ANN.10
CSE4701
Announcements - Spring 2015February 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:
www.engr.uconn.edu/~steve/Cse4701/cse4701inventory.doc Exam Advice
www.engr.uconn.edu/~steve/Cse4701/cse4701mtexamadv.pptx Homework 1 and 2 Solutions Posted – will
Updated with 3 and 4 www.engr.uconn.edu/~steve/Cse4701/cse4701hwsolns.pptx
ANN.11
CSE4701
Homework 4
EER to Relational Conversion www.engr.uconn.edu/~steve/Cse4701/cse4701hw3.pdf
See Chapter 9 Class Notes www.engr.uconn.edu/~steve/Cse4701/cse4701chap9.pptx
ANN.12
CSE4701
EER Diagram
ANN.13
CSE4701
Announcements - Spring 2015February 17, 2015
Homework 3: Assigned Today Due – Monday, February 23, 11:59 pm
Submit to Homework 3 on HuskyCT
ANN.14
CSE4701
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
ANN.15
CSE4701
Homework 3 - Four Problems
Instructions to load DB, generat EER, perform SQL queries http://www.engr.uconn.edu/~steve/Cse4701/
cse4701hw3Instructions.docx For example – the Chinook DB:
See various web links: https://chinookdatabase.codeplex.com/ https://chinookdatabase.codeplex.com/downloads/get/557747
Extract the file: ChinookDatabase1.4_CompleteVersion.zip to get the file: Chinook_MySql.sql
ANN.16
CSE4701
Initial MySQL Workbench Screen
ANN.17
CSE4701
Instructions – import .sql file
ANN.18
CSE4701
Instructions – Query DB
ANN.19
CSE4701
Instructions – Query DB
ANN.20
CSE4701
Instructions – Generate EER
ANN.21
CSE4701
Instructions – Generate EER
ANN.22
CSE4701
Instructions – Generate EER
ANN.23
CSE4701
Chinook EER
ANN.24
CSE4701
Albums and Tracks
If you want to see data:
SELECT * FROM CHINOOK.ALBUM;
SELECT * FROM CHINOOK.TRACK;
ANN.25
CSE4701
Northwind EER
ANN.26
CSE4701
SELECT * FROM NORTHWIND.PRODUCTS;
ANN.27
CSE4701
Look at 1st Problem Homework 37.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” bookJoin on BookID
• Combine the result with theLibrary_Branch table for the“Sharpstown” BranchJoin on BrachID
ANN.28
CSE4701
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
ANN.29
CSE4701
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
ANN.30
CSE4701
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;
ANN.31
CSE4701
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, LNAMEFROM EMPLOYEEWHERE ADDRESS LIKE '%Houston,TX% '
ANN.32
CSE4701
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
CSE 4701
Chapter 9-33
Announcements - Spring 2015February 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.
CSE 4701
Chapter 9-34
Look at 1st Problem Homework 27.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” bookJoin on BookID
• Combine the result with theLibrary_Branch table for the“Sharpstown” BranchJoin on BrachID
CSE 4701
Chapter 9-35
a. 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
CSE 4701
Chapter 9-36
Name: Your name goes here
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
Problem 7.23a or 6.18a
CSE 4701
Chapter 9-37
Announcements - Spring 2015February 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
CSE 4701
Chapter 9-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
CSE 4701
Chapter 9-39
Person
Author
Email LastNameFirstName
PersonID
WRITES
CSE 4701
Chapter 9-40
In Class ER/EER to Relational Conversion
CSE 4701
Chapter 9-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
NEW TABLE STEP 7: N-ARY (3 or MORE)
NEW TABLE STEP 8: INHERITANCE
CSE 4701
Chapter 9-42
ER for Problem 1.1
Phone#
Patient
Drug
Physician
name
address email
SSN
status
price
name
expiration
name
address
specialtyPrimary
N 1
DEA#
Prescribes
refills N
N
dosage
dateFill
requirementpattern
Sold By
Purchasing Contract
start_date end_date
CSE 4701
Chapter 9-43
Tables for ER Diagram NOTE: For clarity used PNAME, MDNAME, DCNAME, DNAME STEP 1:
PATIENT (PNAME, ADDRESS, PHONE#, SSN, EMAIL) PHYSICIAN (MDNAME, ADDRESS, PHONE#, DEA#, EMAIL,
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, EMAIL,
MDNAME)
CSE 4701
Chapter 9-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)
CSE 4701
Chapter 9-45
Patient
Drug
PhysicianSSN
status
price
name
expiration
specialtyPrimary
N 1
Prescribes
refills N
N
dosage
dateFill
requirementpattern
Sold By
Purchasing Contract
start_date end_date
Person
Drug Prescriber
DEA#
name
emailaddress
CSE 4701
Chapter 9-46
Tables for ER Diagram NOTE: For clarity used PNAME, MDNAME, DCNAME, DNAME STEP 1:
PATIENT (PNAME, ADDRESS, PHONE#, SSN, EMAIL) PHYSICIAN (MDNAME, ADDRESS, PHONE#, DEA#, EMAIL,
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, EMAIL,
MDNAME)
CSE 4701
Chapter 9-47
Tables for EER Diagram Inheritance OPTION 1:
PERSON (PNO, PNAME, ADDRESS, PHONE#, EMAIL) DRUGPRESCRIBER (PNO, DEA#) PATIENT (PNO, SSN) PHYSCIAN(PNO, DEA#, SPECIAITY)
Inheritance OPTION 3: TYPE = PATIENT, PHYSICIAN, PRESCRIBER PERSON (PNO, PNAME, ADDRESS, PHONE#, EMAIL, 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)