Question

In: Computer Science

SQL A manufacturing company’s data warehouse contains the following tables. Region region_id (p) region_name super_region_id (f)...

SQL

A manufacturing company’s data warehouse contains the following tables.

Region

region_id (p)

region_name

super_region_id (f)

101

North America

102

USA

101

103

Canada

101

104

USA-Northeast

102

105

USA-Southeast

102

106

USA-West

102

107

Mexico

101

Note: (p) = "primary key" and (f) = "foreign key". They are not part of the column names.

Product

product_id (p)

product_name

1256

Gear - Large

4437

Gear - Small

5567

Crankshaft

7684

Sprocket

Sales_Totals

product_id (p)(f)

region_id (p)(f)

year (p)

month (p)

sales

1256

104

2020

1

1000

4437

105

2020

2

1200

7684

106

2020

3

800

1256

103

2020

4

2200

4437

107

2020

5

1700

7684

104

2020

6

750

1256

104

2020

7

1100

4437

105

2020

8

1050

7684

106

2020

9

600

1256

103

2020

10

1900

4437

107

2020

11

1500

7684

104

2020

12

900

Answer the following questions using the above tables/data:


6. Write a set of SQL statements which will add a row to the Region table for Europe, and then add a row to the Sales_Total table for the Europe region and the Sprocket product (product_id = 7684) for October 2020, with a sales total of $1,500. You can assign any value to the region_id column, as long as it is unique to the Region table. The statements should be executed as a single unit of work. Please note that since the statements are executed as a single unit of work, additional code is needed.

Solutions

Expert Solution

Below is the same tables and its values in the Question  created in SQL;

REGION TABLE:

CREATE TABLE REGION(region_id integer PRIMARY KEY, region_name text,super_region_id integer);

Insert into REGION values(101,"North America",null);
Insert into REGION values(102,"USA",101);
Insert into REGION values(103,"Canada",101);
Insert into REGION values(104,"USA-North East",102);
Insert into REGION values(105,"USA-South East",102);
Insert into REGION values(106,"USA-West",102);
Insert into REGION values(107,"Mexico",101);

PRODUCT TABLE:

CREATE TABLE PRODUCT(product_id integer PRIMARY KEY, product_name text);

Insert into Product values(1256,"Gear-Large");
Insert into Product values(4437,"Gear-Small");
Insert into Product values(5567,"Crankshaft");
Insert into Product values(7684,"Sprocket");

SALES_TOTALS TABLE:

CREATE TABLE SALES_TOTALS(product_id integer, region_id integer,year integer,month integer ,sales integer,PRIMARY KEY(product_id,region_id,year,month) FOREIGN KEY (product_id) references PRODUCT (product_id)FOREIGN KEY (region_id) references REGION (region_id));


Insert into SALES_TOTALS values(1256,104,2020,1,1000);
Insert into SALES_TOTALS values(4437,105,2020,2,1200);
Insert into SALES_TOTALS values(7684,106,2020,3,800);
Insert into SALES_TOTALS values(1256,103,2020,4,2200);
Insert into SALES_TOTALS values(4437,107,2020,5,1700);
Insert into SALES_TOTALS values(7684,104,2020,6,750);
Insert into SALES_TOTALS values(1256,104,2020,7,1100);
Insert into SALES_TOTALS values(4437,105,2020,8,1050);
Insert into SALES_TOTALS values(7684,106,2020,9,600);
Insert into SALES_TOTALS values(1256,103,2020,10,1900);
Insert into SALES_TOTALS values(4437,107,2020,11,1500);
Insert into SALES_TOTALS values(7684,104,2020,12,900);

ANSWER

Below SQL statements inserts a new row to the REGION Table adding Europe Region and also inserts a row to the SALES_TOTALS Table adding  Sprocket product (product_id = 7684) for October 2020, with a sales total of $1,500 for the European Region.

SAVEPOINT SP1;
Insert into REGION values (108,"Europe",null);
SAVEPOINT SP2;
Insert into SALES_TOTALS values(7684,108,2020,10,1500);

Note:you can rollback to any of the savepoints if needed;

The REGION and SALES_TOTAL Tables after executing the statement;

REGION TABLE:

SALES_TOTALS TABLE:


Related Solutions

Complete the following table for H2O. Use data from the steam tables. T, °F P, psia...
Complete the following table for H2O. Use data from the steam tables. T, °F P, psia u, Btu/lbm Phase description 300 782 (Click to select)  Compressed liquid  Saturated mixture  Saturated liquid  Superheated vapor 40 Saturated liquid 500 120 (Click to select)  Saturated mixture  Superheated vapor  Compressed liquid  Saturated liquid 400 400 (Click to select)  Superheated vapor  Saturated liquid  Compressed liquid  Saturated mixture
Experiment with SQL queries on 2 tables: Background: Normalized databases will involve data that is organized...
Experiment with SQL queries on 2 tables: Background: Normalized databases will involve data that is organized into 2 or more tables. However, to answer queries, the data from 2 (or more) tables will need to be joined together to get the relevant information. Join operations in SQL are accomplished in the following manner: Indicate the tables involved in the query in the FROM clause Specify relationship/condition between columns in from the tables. Exercise: For this part of the exercise the...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
Write the SQL DDL to create the following 5 tables for an App store: Publisher, Category,...
Write the SQL DDL to create the following 5 tables for an App store: Publisher, Category, App, AppVersion, AppVersionReview: A Publisher table where each publisher is identified by an integer id and has a name (up to 40 characters). (1 mark) A Category table where each category has an id (integer), a name (up to 50 characters), and a parentId to identify its parent category. The parentId should be a foreign key to the Category table. (1.5 marks) An App...
SQL code Create entities (tables) to represent the following ternary relationship. Note that we are not...
SQL code Create entities (tables) to represent the following ternary relationship. Note that we are not storing all the required information in these entities to simplify it. The underlined attributes are the primary keys. Don’t forget to set the constraints for primary and foreign keys: •A student entity ( bannerId, first name, last name, date of birth) •A course entity ( crnNumber, course name, # of credits) •An examination entity ( examId, exam_type, exam_date). (exam types can be “Midterm”, “Final”,...
Using the HotelDB tables, provide the following result as a screen image. WRITE SQL to retrieve...
Using the HotelDB tables, provide the following result as a screen image. WRITE SQL to retrieve rows from any hotel with Family room types and price less than $150. use hoteldb; CREATE TABLE HOTEL ( hotelNo numeric primary key , name varchar(40) , address varchar(40) , city varchar(200) ); CREATE TABLE ROOM ( roomNo numeric Primary Key , hotelNo numeric References HOTEL , type varchar(20) , price dec(9,2) ); CREATE TABLE GUEST ( guestNo numeric primary key , name varchar(40)...
a) Use truth tables to show that the following are valid arguments: i. [p  (p...
a) Use truth tables to show that the following are valid arguments: i. [p  (p → q)] → q ii. [(p → q) ∧ (q → r)] → (p → r) b) Use truth tables to show the logical equivalence of: i. (p → q) ⇔ (¬p ∨ q ) ii. (¬p ∨ q) ∨ (¬p  q) ⇔ p
For each region of the lac operon on the F' plasmid, I+ P+ Oc Z− Y+ , determine whether the region is wild type
For each region of the lac operon on the F' plasmid, I+ P+ Oc Z− Y+ , determine whether the region is wild type (that is, it produces a functional protein or it's a correct protein binding sequence) or whether the region is mutated. Select all that apply. Select all that apply. The promoter sequence is correct/functional. The repressor protein is produced. The operator sequence is correct/functional. Beta-galactosidase is produced from the lacZ gene. Permease is produced from the lacY...
SQL 9. Link the following two tables: HumanResources.Employee and Sales.SalesPerson then display Employee PK, job title,...
SQL 9. Link the following two tables: HumanResources.Employee and Sales.SalesPerson then display Employee PK, job title, Date of birth, Gender, Sales quotas, Commission percent and bonus. Use an outer join to display all the employee whether they are in sales or not. Make sure to sort by bonus desc. Explain why some of the field from the Sales.SalesPerson table are null.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT