Course2Module4Assignment
Course2Module4Assignment
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
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
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,
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
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
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
match does not occur, insert a row into the Mobile_Bill table with the customer identifier
12/10/2022 Module 4 Assignment on SQL Statements for Data Integration Page 3
8. Write an Oracle INSERT FIRST statement to insert rows from a mobile customer table
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
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. For this problem, you should study
the extended example for the last PostgreSQL slide (slide 11). The extended example is only
12/10/2022 Module 4 Assignment on SQL Statements for Data Integration Page 4
contained the file with Lesson 7 examples. This slide document does not contain this
example.