Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMPE Database Systems Workshop June 12 Class Meeting

Similar presentations


Presentation on theme: "CMPE Database Systems Workshop June 12 Class Meeting"— Presentation transcript:

1 CMPE 180-38 Database Systems Workshop June 12 Class Meeting
Department of Computer Engineering San Jose State University Summer 2017 Instructor: Ron Mak

2 Midterm Solutions: Question 1
Briefly describe the necessary steps to normalize a proper relational table to first normal form (1NF). No steps are necessary. Any proper relational table is already in first normal form.

3 Midterm Solutions: Question 2
Briefly describe the necessary steps to normalize a proper relational table that has a non-composite primary key to second normal form (2NF). No steps are necessary. Second normal form removes partial functional dependencies, where fields are dependent on a component of the composite primary key. If the primary key is non-composite, there are no partial functional dependencies.

4 Midterm Solutions: Question 3.a
Year Department Leader ID Amount 2015 CMPE Sigurd Meldal $12,000 CS Sami Khuri $11,000 2016 Math Bem Cayco $10,000 Xiao Su You want to record the fact that in the year 2017, Mary Jane, who has ID and does not belong to a department, is the leader of the Spartan Committee. Briefly explain why you can or cannot add a 2017 row for her and enter nulls for the Department and Amount fields. You cannot add a 2017 row where the Department field is null. The Department field is part of the composite primary key. Therefore, leaving that field null violates the entity integrity constraint.

5 Midterm Solutions: Question 3.b
Year Department Leader ID Amount 2015 CMPE Sigurd Meldal $12,000 CS Sami Khuri $11,000 2016 Math Bem Cayco $10,000 Xiao Su Normalize this table to third normal form (3NF). ID  Leader is a transitive functional dependency. We can move those columns into a new table: Year Department ID Amount ID Leader

6 Midterm Solutions: Question 3.c
Give a good reason why you may want to leave this table unnormalized. The original table has faster query response.

7 Midterm Solutions: Question 4.a

8 Midterm Solutions: Question 4.b

9 Midterm Solutions: Question 5.a
Display the ProductID and ProductName of the cheapest product without using a nested query. SELECT productid, productname FROM product ORDER BY productprice LIMIT 1;

10 Midterm Solutions: Question 5.b
Repeat the above task with a nested query. SELECT productid, productname FROM product WHERE productprice = (SELECT MIN(productprice) FROM product);

11 Midterm Solutions: Question 5.c
Display the ProductID, ProductName, and VendorName for products whose price is below the average price of all products SELECT p.productid, p.productname, v.vendorname FROM product p, vendor v WHERE p.vendorid = v.vendorid AND productprice < (SELECT AVG(productprice) FROM product);

12 Midterm Solutions: Question 5.d
Display the ProductID for the product that has been sold the most (i.e., that has been sold in the highest quantity). SELECT productid FROM soldvia GROUP BY productid HAVING SUM(noofitems) = (SELECT MAX(SUM(noofitems)) GROUP BY productid);

13 Midterm Solutions: Question 5.e
The following query retrieves each product that has more than three items sold within all sales transactions: SELECT productid, productname, productprice FROM product WHERE productid IN (SELECT productid FROM soldvia GROUP BY productid HAVING SUM(noofitems) > 3); Rewrite it without using a nested query but instead with a join: SELECT p.productid, productname, productprice FROM product p, soldvia s WHERE p.productid = s.productid GROUP BY p.productid, p.productname, p.productprice HAVING SUM(s.noofitems) > 3;

14 Midterm Solutions: Question 6.a

15 Midterm Solutions: Question 6.b

16 Final Project Put your emphasis on data management. Data models:
How you manage the data that are you are using. Data models: Operational tables Analytical tables Data operations: Queries and updates of the operational tables. How the analytical tables are loaded. Queries of the analytical tables for data analysis. You can use actual downloaded data or data created by data generation tools.

17 Final Project, cont’d User application that invokes the data operations. Web-based or desktop-based. PHP, Java, etc. Fancy GUI or data visualization not necessary. How well did you use the technologies you learned during the semester? RDBM, DW, XML, data virtualization (CIS), NoSQL Not all technologies have to be used.

18 Final Project, cont’d Written report What is the application?
What data did you use, and where did you get it? Overview of your data models (in words). ER diagram Relational schemas Star schemas Operational and analytical queries Example user actions and screen shots of results.

19 Detailed vs. Aggregated Fact Tables
In a detailed fact table, each row contains data about a single fact. In an aggregated fact table, each row contains a summary of multiple facts. Such as a sum (aggregation) of all sales of a product in a particular store during a single day.

20 Detailed Fact Table Example
Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

21 Detailed Fact Table Example, cont’d
Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

22 Detailed Fact Table Example, cont’d
Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Each fact table record contains data about one sales fact.

23 Line-Item Detailed Fact Table
Each row is a single line item of a particular transaction. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

24 Transaction-Level Detailed Fact Table
Each row is a single transaction. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

25 Aggregated Fact Table Example
Aggregated fact table DPCS: Total amount sold in dollars and units on a particular day for a particular product for a particular customer for a particular store. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

26 Aggregated Fact Table Example, cont’d
Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

27 Aggregated Fact Table Example, cont’d
Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

28 Aggregated Fact Table Example, cont’d
Aggregated fact table DCS: Total amount sold in dollars and units on a particular day for a particular customer for a particular store for all products. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

29 Aggregated Fact Table Example, cont’d
Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

30 Aggregated Fact Table Example, cont’d
Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

31 Aggregated Fact Table Example, cont’d
Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

32 Break

33 Granularity of the Fact Table
Fine level of granularity: Detailed fact table. Courser level of granularity: Aggregated fact table. Finer granularity: More analysis power. Courser granularity: Faster queries.

34 Granularity of the Fact Table, cont’d
Granularity can also depend on how the data is collected and loaded into the fact table. Example: Load only daily sales. But then you lose the ability to analyze sales by the hour. A solution: Keep both fine-grained and aggregated tables and have them share the dimension tables.

35 Granularity of the Fact Table, cont’d
Good DW design involves deciding which aggregates are worth storing as tables. The base fact tables contain data at the finest level of granularity required for analysis. Facts can be pre-summarized in aggregate tables at granularity levels that are determined to be optimal for certain analysis procedures.

36 Granularity of the Fact Table, cont’d
Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

37 Slowly Changing Dimensions
In a typical dimension of a star schema, either: The values of a dimension’s attributes do not change or change extremely rarely. Examples: store address, customer gender OR: The values of a dimension’s attributes change occasionally and sporadically over time. Example: customer address Three approaches to handling slowly changing dimensions: Type 1, Type 2, and Type 3.

38 Slowly Changing Dimensions: Type 1
Simply change the value in the dimension table’s record. Often used to correct errors. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

39 Slowly Changing Dimensions: Type 2
Preserve history by creating an additional row with the new value. Often used with timestamps. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Now you see why this analytical table uses separate a CustomerKey rather than the CustomerID.

40 Slowly Changing Dimensions: Type 3
Create “previous” and “current” columns. Only a fixed number of changes is possible. Record only a limited history. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

41 Snowflakes Dimension tables can be unnormalized.
Fewer tables = faster joins = faster queries. Update anomalies are not a concern. Dimension tables are slowly changing. Updates happen rarely if at all. An undesirable snowflake results from unnecessarily normalizing dimension tables.

42 Snowflakes, cont’d Unnormalized dimension tables. Database Systems
by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

43 X X Snowflakes, cont’d Avoid creating a snowflake! Database Systems
by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

44 DW Architecture: Bill Inmon Approach
Normalized Data Warehouse Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

45 DW Architecture: Ralph Kimball Approach
Dimensionally Modeled Data Warehouse Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

46 DW Architecture: Independent Data Marts
Inferior – Do not use! Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

47 Online Transaction Processing (OLTP)
Online: The computer responds immediately or very quickly. online ≠ Internet OLTP online transaction processing operational database = OLTP system Update and query operational data. Present data Generate reports

48 Online Analytical Processing (OLAP)
Query data from data warehouses and/or data marts to analyze and present data. OLAP tools support decision making. OLAP tools are read only. OLAP operations drill up and drill down slice and dice pivot

49 OLAP Drill Up and Drill Down
Drill through dimension hierarchies. Examples: Location: country  state  region  city  store Time: year  quarter  month  week  day  hour Drill up AKA roll up Make the data granularity coarser. Aggregate the data. Drill down Make the data granularity finer.

50 OLAP Drill Up and Drill Down, cont’d

51 OLAP Drill Up and Drill Down, cont’d

52 Slice and Dice Slice: Select one value of a dimension attribute.

53 Slice and Dice Dice: Select attribute values from two or more dimensions.

54 Pivot Pivot: Reorganize query results by rotation.

55 Conformed Dimensions When multiple star schemas share a common set of dimensions, the dimensions are called conformed dimensions. Conformed dimensions enable analyses to span multiple star schemas, where the schemas share a common view of the world. For example, all the schemas must share a common view of what a customer is. Drill across: A OLAP operation that spans multiple star schemas.

56 OLAP/BI Tools Users can query fact and dimension tables by using simple point-and-click query-building applications. Based on user actions, the tool generates and executes the SQL code on the data warehouse or data mart. SQL code to drill up or down, slice or dice, or pivot. Example OLAP/BI tools IBM Cognos, Oracle BI, TIBCO Spotfire, Tableau

57 OLAP/BI Tools, cont’d Typical OLAP tool layout Database Systems
by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

58 OLAP/BI Tool Demos RadarSoft: Telerik: See also:

59 Assignment #4 Team assignment.
Perform OLAP operations on your dimensional model from Assignment #3. For each of the following operations, write and execute SQL queries using your sample data: drill up drill down slice dice

60 Assignment #4, cont’d For each OLAP operation, show the query, and “before” and “after” query output. Example: Do a query that shows quarterly results. Then for a drill down, do a query that shows monthly results. For a drill up, do a query that aggregates and shows yearly results. Submit a zip file into Canvas containing: Dump of your dimensional model. SQL queries and text files containing the results.


Download ppt "CMPE Database Systems Workshop June 12 Class Meeting"

Similar presentations


Ads by Google