Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Module 4 assignment provides practice with SQL statements for data integration. A file in the same website item contains table definitions for the problems.

The Module 4 assignment provides practice with SQL statements for data integration. A file in the same website item contains table definitions for the problems. Problems 1 to 9 involve Oracle SQL for the MERGE and multiple table INSERT statements. Problems 10 to 12 involve the INSERT ... ON CONFLICT statement for PostgreSQL. You are encouraged to use both DBMSs to complete the assignment. If you only have one DBMS installed, you should provide your best solution without execution for statements using the other DBMS.
1. Write an Oracle SQL MERGE statement to combine the SSItem dimension table and the SSItemChanges1 change table. The associated document contains CREATE TABLE and INSERT statements for both tables. Each matching row of SSItemChanges1 contains values for both modified and non-modified columns.
2. Write an Oracle SQL MERGE statement to combine the SSItem dimension table and the SSItemChanges2 change table. The associated document contains CREATE TABLE and INSERT statements for both tables. Each matching row of SSItemChanges2 contains new values for modified columns and null values for non-modified columns.
3. Write an Oracle SQL INSERT ALL statement to insert rows of the ProductSale1 table into four tables (ProductSales2018, ProductSales2019, ProductSales2020, and ProductSales2021). The associated document contains CREATE TABLE and INSERT statements for all tables. Note that the target tables lack the SalesYear column. If SalesYear equals 2018, insert a row into ProductSales2018. The comparisons for the other tables only differ on the SalesYear value and suffix in the name of the target table. You should compute the SalesAmt column in each target table as the sum of the quarter sales (Qtr1, Qtr2, Qtr3, and Qtr4) in the corresponding row of the ProductSale table.
4. On Problem 3, is the number of the rows in the target tables the same when using INSERT FIRST versus INSERT ALL? Justify your answer by writing and executing an INSERT FIRST statement.
5. Write an Oracle SQL INSERT FIRST statement to insert rows of the ProductSale2 table into three target tables (Year_Low_Sales, Year_Mid_Sales, and Year_High_Sales). The associated document contains CREATE TABLE statements for all tables. Insert a row into Year_Low_Sales when annual sales (sum of Qtr1, Qtr2, Qtr3, and Qtr4) are less than 4,000. Insert a row into Year_Mid_Sales when annual sales are greater than or equal 4,000 and less than 7,000. Insert remaining rows into Year_High_Sales. You should compute the SalesAmt column in each target table as the sum of the quarter sales (Qtr1, Qtr2, Qtr3, and Qtr4) in the corresponding row of the ProductSale table.
6. On Problem 5, is the number of the rows in the target tables the same when using INSERT FIRST versus INSERT ALL? Justify your answer by writing and executing an INSERT ALL statement.
7. Write an Oracle MERGE statement to combine the Mobile_Bill table with the Mobile_Usage table matching on CustId. The associated document contains CREATE TABLE statements for both tables. The Mobile_Bill table contains the most recent bill with the current amount (CurrentAmt) and past amount (PastAmt). When a match occurs, update the Mobile_Bill.CurrentAmt column as minutes used (Mobile_Usage.MinutesUsed) times 0.05 and the Mobile_Bill.PastAmt column as the previous current amount (Mobile_Bill.CurrentAmt) plus the previous past amount (Mobile_Bill.PastAmt). When a match does not occur, insert a row into the Mobile_Bill table with the customer identifier (Mobile_Usage.CustId), minutes used (Mobile_Usage.MinutesUsed) times 0.05, and 0 for the past amount (Mobile_Bill.PastAmt).
8. Write an Oracle INSERT FIRST statement to insert rows from a mobile customer table (Mobile_Customer) into three tables (Mobile_Gold, Mobile_Silver, and Mobile_Bronze) based on a customers current revenue amount (Mobile_Customer.CurrentAmt). The associated document contains CREATE TABLE statements for all tables. If the current revenue amount is greater than or equal to 150, insert the mobile customer row into the Mobile_Gold table. If the current revenue amount is greater than or equal to 100, insert the mobile customer row into the Mobile_Silver table. Otherwise, insert the mobile customer row into the Mobile_Bronze table.
9. On Problem 8, is the number of the rows in the target tables the same when using INSERT FIRST versus INSERT ALL? Justify your answer by writing and executing an INSERT ALL statement.
10. Write a PostgreSQL INSERT .... CONFLICT ON statement for the requirements in Problem 1.
11. Write a PostgreSQL INSERT .... CONFLICT ON statement for the requirements in Problem 2.
12. Modify the solution to Problem 11 to work with NOT NULL constraints on all columns of SSItem except for ItemId. INSERT statements have been modified in the change table in the associated document. Text columns (VARCHAR and CHAR) have a value of NV for no value. Numeric columns have a value of 0 for no value.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

More Books

Students also viewed these Databases questions

Question

Homework 1 : ER modeling

Answered: 1 week ago