Announcements - Spring 2015 March 2, 2015

Slides:



Advertisements
Similar presentations
ER Modeling Case Studies
Advertisements

More Diagramming & Practice with Relationship Modeling
SQL Database for a Book Store Clinton McKay. Explanation The database contains information about the books held in stock, their authors, publishers, customers,
Exercise 1 Consider the ER diagram below. Assume that an employee may work in up to two departments or may not be assigned to any department. Assume that.
ER to Relational Mapping. Logical DB Design: ER to Relational Entity sets to tables. CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER,
FEN Introduction to the database field: Quality checking table design: Design Guidelines Normalisation Seminar: Introduction to relational.
Logical DB Design: ER to Relational Entity sets to tables. Employees ssn name lot CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER, PRIMARY.
ER Modeling Case Studies
ER Modeling Case Studies
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Huiswerk Lees delen 3.2, 3.3 van hoofdstuk 3. opgaven voor hoofdstuk 2: modelleeropgave 5.
CSCI3170 Introduction to Database Systems
NORMALIZATION FIRST NORMAL FORM (1NF): A relation R is in 1NF if all attributes have atomic value = one value for an attribute = no repeating groups =
IELM 511: Information System design Introduction Part I. ISD for well structured data – relational and other DBMS Part II. ISD for systems with non-uniformly.
Ms. Hatoon Al-Sagri CCIS – IS Department Normalization.
E/R – ODL – UML CS145 Monday November 26 Sanaz Motahari-Asl.
DATABASE APPLICATION DEVELOPMENT SAK 3408 Database Design II (week 3)
Design Guidelines Normalisation Table Design. Informal Design Guidelines Table Semantics A table should hold information about one and only one entity/concept.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Reduction of an E-R Schema to Tables A database which conforms to an E-R diagram can be represented.
Mapping ERM to relational database
INFORMATION TECHNOLOGY IN BUSINESS AND SOCIETY SESSION 16 – SQL SEAN J. TAYLOR.
CSE 4701 Chapter 9-1 Chap 9 (6/5e): ER to Relational Transformation Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Relational Database Design by ER- and EER-to-Relational Mapping.
Daniel AdinugrohoDatabase Programming 1 DATABASE PROGRAMMING Lecture on 29 – 04 – 2005.
ER to Relational Mapping. Logical DB Design: ER to Relational Entity sets to tables. CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER,
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 6 NORMALIZATION FOR RELATIONAL DATABASES Instructor Ms. Arwa Binsaleh.
Homework 1 Solution.
CSE 441: Systems Analysis & Design
CHAPTER 2. FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
CSCI3170 Introduction to Database Systems
Chapter 1 Overview of Database Concepts Oracle 10g: SQL
Instructor :Huda Al-Omair
1 Chapter 1 Overview of Database Concepts. 2 Chapter Objectives Identify the purpose of a database management system (DBMS) Distinguish a field from a.
CSE 4701 Chaps15&16-1 Chap 15 & 16 6e e: Relational DB Design, Functional Dependencies and Normalization Prof. Steven A. Demurjian, Sr. Computer.
Lecture 2 An Overview of Relational Database IST 318 – DB Admin.
Other SQL Query Examples
CMPE 226 Database Systems September 16 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
Final Exam Guide PHP NOTE: PHP CODE WILL BE BLUE, HTML IS BLACK EXAMPLE
Normalization A technique that organizes data attributes (or fields) such that they are grouped to form stable, flexible and adaptive entities.
FEN Quality checking table design: Design Guidelines Normalisation Table Design Is this OK?
Chapter 1Introduction to Oracle9i: SQL1 Chapter 1 Overview of Database Concepts.
Entity-Relationship (ER) Modelling ER modelling - Identify entities - Identify relationships - Construct ER diagram - Collect attributes for entities &
Chapter 5-1 CSE 4701 In Class SQL Queries – Part II n Homework 3 from Spring 2015 n Problem 6.18 from the 6 th edition done in SQL and NOT relational expressions.
1 The Information School of the University of Washington Dec 1fit advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.
CS499 Project #3 XML mySQL Test Generation Members Erica Wade Kevin Hardison Sameer Patwa Yi Lu.
E-R to Relational - Basic
ANN.1 CSE4701 Problem th ed  Consider the table:  Consider the table: Orders (O#,I#,Odate, Cust#, Total_amount, Qty_ordered, Total_price, Discount%)
BSA206 Database Management Systems Lecture 2: Introduction to Oracle / Overview of Database Concepts.
Data modeling Process. Copyright © CIST 2 Definition What is data modeling? –Identify the real world data that must be stored on the database –Design.
CMPT 258 Database Systems Midterm Review. Regarding the Exam Oct 15 Thursday Close book Cheat sheet (1 side of an A4 paper)
Introduction to Database Systems
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 5 (Part a): Logical Database Design and the Relational Model Modern Database Management.
COMP 430 Intro. to Database Systems Entity-Relationship Diagram Basics Slides use ideas from Chris Ré.
COMP 430 Intro. to Database Systems ER Design Considerations Slides use ideas from Chris Ré.
IE 423 – Design of Decision Support Systems Data modeling and database development.
Lecture 4: Logical Database Design and the Relational Model 1.
What Is Normalization  In relational database design, the process of organizing data to minimize redundancy  Usually involves dividing a database into.
Chief Financial Officers List
Chapter 4: Logical Database Design and the Relational Model
CSIS 115 Database Design and Applications for Business
DBMS LAB SESSION Pavan Kumar M.P B.E ,M.Sc(Tech) by Research,(Ph.D)
Payroll Management System
ER Modeling Case Studies
INFO/CSE 100, Spring 2005 Fluency in Information Technology
From ER to Relational Model
Session 2 Welcome: The seventh learning sequence
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
ER Modeling Case Studies
ER Modeling Case Studies
INFO/CSE 100, Spring 2006 Fluency in Information Technology
Presentation transcript:

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???

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#

Problem 15.29 6th 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%)

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

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%)

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

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)

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)

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)

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: 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

Homework 4 EER to Relational Conversion See Chapter 9 Class Notes www.engr.uconn.edu/~steve/Cse4701/cse4701hw3.pdf See Chapter 9 Class Notes www.engr.uconn.edu/~steve/Cse4701/cse4701chap9.pptx

EER Diagram

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

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

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

Initial MySQL Workbench Screen

Instructions – import .sql file

Instructions – Query DB

Instructions – Query DB

Instructions – Generate EER

Instructions – Generate EER

Instructions – Generate EER

Chinook EER

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

Northwind EER

SELECT * FROM NORTHWIND.PRODUCTS;

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

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

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

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;

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% '

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

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.

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

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

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

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

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

WRITES Author PersonID Email FirstName LastName Person

In Class ER/EER to Relational Conversion

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

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

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)

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)

   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

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)

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)