Sql script-creating the database and inserting data

Assignment Help PL-SQL Programming
Reference no: EM13169897

CONSIDER THE FOLLOWING SET OF DATABASE TABLES.

The diagram shows a database made up of 6 tables with all primary keys underlined. Please take note of foreign keys (most of them carry the same names as the corresponding primary keys they reference):

1933_Creating the database and inserting data.png

CUS_CODE in INVOICE, INV_NUMBER & P_CODE in LINE, and V_CODE in PRODUCT. The only exception to the naming convention is the EMP_MGR foreign key in EMPLOYEE which references the EMPLOYEE table in a recursive relationship.

- In addition to the above six tables, the script creates two tables V (default vendor table data) and P (default product table data). The only purpose for tables V and P is to demonstrate bulk insert - i.e. how to copy data from one table to another. E.g., to copy all records from table V to Vendor we issue the following: INSERT INTO VENDOR (SELECT * FROM V).

- Notice how I didn't include a FOREIGN KEY constraint in EMPLOYEE to reference itself (in order to implement the recursive relationship manages) because we still have not yet created the table. This has to be done separately as shown below AFTER creating the EMPLOYEE table: ALTER TABLE EMPLOYEE ADD FOREIGN KEY (EMP_MGR) REFERENCES EMPLOYEE;

I. Part 1: Understanding the SQL script, creating the database and inserting data

1. Double-click on the myCompany.SQL script file which will automatically put a copy of the script in the command input sub-window of SQL Developer. [or go into SQL Developer and do a File -> open to open it that way if necessary]

2. Go through the file and make sure you understand every single line of code in it before you proceed.

3. When done, press the Run Script (NOT the Run Statement) button in SQL Developer and you should notice the output of all commands appear sequentially in the output area.

II. Part 2: Writing SQL SELECT statements (one SQL statement per problem):

1. Display all product information for products that contain the string ‘saw' in their description.

2. Display all product information for products currently selling for less than $20.00 and which have more than 100 units in stock (recorded in attribute P_QOH or quantity on hand).

3. Display all product information for products currently selling for less than $20.00 or which have more than 100 units in stock (recorded in attribute P_QOH or quantity on hand).

4. Display the product code, description and price for products provided by vendor 21344.

5. Display the product code, description, price and price after discount (a computed column that uses the P_PRICE and P_DISCOUNT (a percent discount) --- name the computed column NewPrice) for products for which no vendor is specified in table PRODUCT.

6. Display the product code, product description and vendor name for products provided by vendors located in the state of TN.

7. Display the full names of employees who manage other employees, ordered by last name.

8. Display the count of distinct products ordered so far by customers (i.e. exist in table LINE).

9. For every manager, display the manager employee code along with the total number of employees s/he manages.

10. Display the product description, the full customer name and the customer balance for products ordered by customers having a customer balance between $100.00 and $500.00 (inclusive of both). Order by customer last name, then first name, then initial.

11. For every invoice, display the invoice number and the total dollar amount for all products purchased in the invoice, ordered by invoice number in descending order.

12. For every invoice, display the invoice number, invoice date and the total dollar amount for all products purchased in the invoice, ordered by invoice number in descending order and then by invoice date in ascending order.

III. Part 3: Creating an SQL VIEW:

13. Create an SQL view called VENDOR_PRODUCTS_TOTALS that shows the vendor name, vendor code and the total number of products provided by the vendor but only for vendors providing two or more products. When done, issue a select * from VENDOR_PRODUCTS_TOTALS statement to display the contents of view VENDOR_PRODUCTS_TOTALS and include them in your report.

IV. Part 4: Writing UPDATE and DELETE SQL statements:

PS: if you ever need to UNDO changes made to the database by an UPDATE or DELETE statement, issue command rollback in the command input sub-window of SQL Developer.

14. Start by issuing a select * from product statement. Copy the results into your report. Then, create and run an SQL update statement which changes the P_DISCOUNT to 0.03 percent for all products that currently have a discount of 0. Finally issue a select * from product statement after the update and copy the results into your report. This will show you the change produced by your update statement.

15. Start by issuing a select * from product statement. Copy the results into your report. Then, create an SQL update statement which doubles the P_DISCOUNT for all products provided by vendors in TN or FL. Finally issue a select * from product statement after the update and copy the results into your report.

16. Start by issuing a select * from LINE statement. Copy the results into your report. Then, create an SQL delete statement to delete invoice lines that include 2 or more units of product code ‘23109-HB'. Finally issue a select * from LINE statement after the delete and copy the results into your report. This should show you the change produced by your delete statement.

Reference no: EM13169897

Questions Cloud

Find the temperature of the water : A mixture of 4.0 mol of H2 and 2.0 mol of O2 is placed in a sealed evacuated container made of a perfect insulating material at 27C. The mixture is ignited with a spark and it reacts to form liquid water. Find the temperature of the water.
What is the molarity of the stock solution of luminol : the forensic technician at a crime scene has just prepared a luminol stock solution by adding 11.0 of luminol to creating a solution with a total volume of 75.0 . What is the molarity of the stock solution of luminol?
Which of the following pairs has about same atomic radius : Which of the following pairs has about the same atomic radius?
What is the temperature rise : The molar heat of combustion of methanol (molar mass = 32.0g/mol) is -757kJ/mol. If 2.00 g of methanol is placed in a bomb calorimeter with a heat capacity of 6.50 kJ/degree C what is the temperature rise when the sample is combusted?
Sql script-creating the database and inserting data : Understanding the SQL script, creating the database and inserting data and display all product information for products that contain the string ‘saw' in their description.
The female vote : "The Female Vote" Women have had the right to vote in this country for less than one hundred (100) years - just since 1920. Much has been written about the power of "the female block" and national candidates can win or lose based on their appeal to t..
Why does absorbance vs concentration calibration curve need : Why does absorbance vs concentration calibration curve need not pass through origin (0,0) looking at beer lambert law?
What ions will the following elements form : what ions will the following elements form?
Why does this produce a lightheaded feeling : When runners or other athletes practice at high altitudes pressure is reduced. What then will be the effect on the [O2] in their blood? Why does this produce a lightheaded feeling?

Reviews

Write a Review

PL-SQL Programming Questions & Answers

  Script that creates and calls a function named

Write a script that creates and calls a function named fnDiscountPrice that calculates the discount price of an item in the OrderItems table (discount amount subtracted from item price). To do that, this function should accept one parameter for th..

  Can we offer an example of a query

Can we offer an example of a Query in which we can use a parentheses to affect the order of execution in which the WHERE Clause has both AND and OR Logical Operators?

  Create student sorting table

Student.txt in the attachment contains the roster of a class. Each student object has the following fields: student id, last name, first name, academic level.Create a RosterClass to store the student database in vector.

  Explaining sql insert statement to insert new row in cds

Write down a SQL insert statement to insert new row in "CDS" table.

  F does not logically imply

Given R = (J,K,L ) and the set F of FDs J -> K and L -> K , show that F does NOT logically

  Write a xquery which returns all concert titles

Write a XQuery which returns all concert titles whose type is chamber orchestra where average ticket price is at least $50.

  If the value for the listprice column is a negative number

If the value for the ListPrice column is a negative number, the stored procedure should raise an error that indicates that this column doesn't accept negative numbers. Similarly, the procedure should raise an error if the value for the DiscountPer..

  Write select statement to return those rows with due balance

Write SELECT statement which returns those rows with the balance due greater than 1000. Sort result set by InvoiceTotal, with largest invoice first.

  Create a view named productsummary

Create a view named ProductSummary that uses the view you created in exercise 4. This view should return some summary information about each product.

  Statement to display the sku, sku_description

write an sql statement to display the SKU, SKU_Description, WareHouse ID, and QuantityOnHand for all products having a QuantityOnOrder equal to 0. Sort the results in descending order by WareHouse ID and in ascending order by SKU

  Query to show customers were missing for existing orders

As DBA, your manager called a meeting and asked why there are so many orders for customers that don't exist in the customer table. Write query which would shows which customers were missing for existing orders. Use a join or a subquery.

  Write programme in oracle to make employee table

List the employee_id and employee_name of the employees form the l_employees table with the top 4 credit limits.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd