Question: Create and submit a sql script to answer all the questions. Make sure to add comments in the document to add title for each question.

Create and submit a sql script to answer all the questions. Make sure to add comments in the document to add title for each question. Use Chapter 8 database script to create your database that you can use to test your script: Ch08_ConstructCo_MySQL.sql and Ch08_SaleCo_MySQL.sql 1. Write the SQL code that will create only the table structure for a table named EMP_1. This table will be a subset of the EMPLOYEE table. The basic EMP_1 table structure is summarized in the following table. Use EMP_NUM as the primary key. Note that the JOB_CODE is the FK to JOB so be certain to enforce referential integrity. Your code should also prevent null entries in EMP_LNAME and EMP_FNAME. 2. Having created the table structure in Problem 1, write the SQL code to enter the first two rows for the table shown in Figure P8.2. Each row should be inserted individually, without using a subquery. Insert the rows in the order that they are listed in the figure. 3. Using the EMPLOYEE table that already exists, use a subquery to insert the remaining rows from the EMPLOYEE table into the EMP_1 table. Remember, your subquery should only retrieve the columns needed for the EMP_1 table and only the employees shown in the figure. 4. Write the SQL code that will save the changes made to the EMP_1 table (if supported by your DBMS).5. Write the SQL code to change the job code to 501 for the person whose employee number (EMP_NUM) is 107.6. Write the SQL code to delete the row for William Smithfield, who was hired on June 22,2008, and whose job code is 500.(Hint: Use logical operators to include all of the information given in this problem. Remember, if you are using MySQL, you will have to first disable "safe Mode,)7. Write the SQL code to create a copy of EMP_1, including all of its data, and naming the copy EMP_2.8. Using the EMP_2 table, write the SQL code that will add the attributes EMP_PCT and PROJ_NUM to EMP_2. The EMP_PCT is the bonus percentage to be paid to each employee. The new attribute characteristics are: EMP_ DECIMAL(4,2) PROJ_NUM CHAR(3)9. Using the EMP_2 table, write the SQL code to change the EMP_PCT value to 3.85 for the person whose employee number (EMP_NUM) is 103.10. Using the EMP_2 table, write a single SQL command to change the EMP_PCT value to 5.00 for the people with employee numbers 101,105, and 107. Use the following table to answer the remaining questions. 11. Create a trigger named trg_line_total to write the LINE_TOTAL value in the LINE table every time you add a new LINE row. (The LINE_TOTAL value is the product of the LINE_UNITS and LINE_PRICE values.)12. Create a trigger named trg _line_prod that automatically updates the quantity on hand for each product sold after a new LINE row is added. 13. Create a stored procedure named pre_inv _amounts to update the INV_SUBTOTAL, INV_TAX, and INV_TOTAL. The procedure takes the invoice number as a parameter. The INV_SUBTOTAL is the sum of the LINE_TOTAL amounts for the invoice, the INV_TAX is the product of the INV_SUBTOTAL and the tax rate (8 percent), and the INV_TOTAL is the sum of the INV_SUBTOTAL and the INV_TAX. 14. Create a procedure named pre_cus_balance_update that will take the invoice number as a parameter and update the customer balance. (Hint: You can use DECLARE to define a TOTINV numeric variable that holds the computed invoice total.)
Create and submit a sql script to answer all the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!