Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part I Anonymous PL / SQL block Consider the table C _ WORKER with attributes WID, WName, and WSalary, and the table TAXVALUES with attributes
Part I Anonymous PLSQL block Consider the table CWORKER with attributes WID, WName, and WSalary, and the table TAXVALUES with attributes MaxAmount and TaxRate, defined and populated by the following script: DROP TABLE CWORKER CASCADE CONSTRAINTS; CREATE TABLE CWORKER WID CHAR PRIMARY KEY, WName VARCHAR WSalary NUMBER; INSERT INTO CWORKER VALUES 'Alfred', ; INSERT INTO CWORKER VALUES 'Bernard', ; INSERT INTO CWORKER VALUES 'Cayenne', ; INSERT INTO CWORKER VALUES 'Delta', ; INSERT INTO CWORKER VALUES 'Eliza', ; INSERT INTO CWORKER VALUES 'Francis', ; INSERT INTO CWORKER VALUES 'Garfield', ; SELECT FROM CWORKER; DROP TABLE TAXVALUES CASCADE CONSTRAINTS; CREATE TABLE TAXVALUES MaxAmount NUMBERmaximum tax amount TaxRate NUMBERtax rate ; INSERT INTO TAXVALUES VALUES ; SELECT FROM TAXVALUES; COMMIT; Write a script containing just an anonymous PLSQL block that will do the following: First, read the maximum tax amount and tax rate from the TAXVALUES table, store them in variables, and display their values. You may assume that the TAXVALUES table contains exactly one record. Next, for each worker in the CWORKER table, compute the amount of tax to be withheld from their salary, as follows: If the salary times the tax rate is less than the maximum tax amount, then the amount of tax to be withheld is the salary times the tax rate. So for the values in the sample TAXVALUES table, a worker with a salary of would have a tax amount of withheld.If the salary times the tax rate is greater than or equal to the maximum tax amount, then the amount of tax to be withheld is the maximum tax amount. So for the values in the sample TAXVALUES table, a worker with a salary of would have a tax amount of withheld, since exceeds Output each workers information on a single line, showing their ID salary, tax amount, and net pay ie the salary minus the amount of tax withheld Add a to the end of each line in which the maximum tax amount is withheld. Also, compute the total tax withheld from all the workers salaries and report that total at the end. For the sample data given, the output should be: Tax rate: Maximum Tax: : : : : : : : Total tax withheld: Note: Be aware that this is just an example your anonymous PLSQL procedure and trigger should work in general, not just for the given sample data. Part II Triggers Consider the table TAUDIT with attributes WID, OLDSal, NEWSal, NEWTax, auditDate defined and populated by the following script: DROP TABLE TAUDIT CASCADE CONSTRAINTS; CREATE TABLE TAUDIT WID CHAR REFERENCES CWORKERWID OLDSal NUMBER NEWSal NUMBER OLDTax NUMBER NEWTax NUMBER auditDate DATE DEFAULT SYSDATE, PRIMARY KEY WID auditDATE; Write a SQL trigger that will do the following: The trigger should be named NewTaxByLastFirst replace Last and First with your last and first names, respectively. In my case, it should be NewTaxByPerazaEliecer The trigger should be fired after a salary of a worker changes. It only should run for those workers not withholding the maximum tax before the update. It should insert all the information requested in the TAUDIT table for each time the trigger body runs once for each row meeting the condition It should output each workers information on single line, showing their ID old salary, old tax amount, new salary, new tax amount, and difference of tax withheld. The output should look like this: : : : : Note: this output is the result of executing UPDATE CWORKER SET WSalary WSalary; Note: this is the result of running SELECT FROM taudit; after the above UPDATE has run. The tax rate and max amount may be hard coded for the trigger condition but must be retrieved from the taxvalues table when used in the body of the trigger. PLEASE ANSWER PART I AND II I WILL GIVE THUMBS UP
Part I Anonymous PLSQL block Consider the table CWORKER with attributes WID, WName, and WSalary, and the table TAXVALUES with attributes MaxAmount and TaxRate, defined and populated by the following script: DROP TABLE CWORKER CASCADE CONSTRAINTS; CREATE TABLE CWORKER WID CHAR PRIMARY KEY, WName VARCHAR WSalary NUMBER; INSERT INTO CWORKER VALUES 'Alfred', ; INSERT INTO CWORKER VALUES 'Bernard', ; INSERT INTO CWORKER VALUES 'Cayenne', ; INSERT INTO CWORKER VALUES 'Delta', ; INSERT INTO CWORKER VALUES 'Eliza', ; INSERT INTO CWORKER VALUES 'Francis', ; INSERT INTO CWORKER VALUES 'Garfield', ; SELECT FROM CWORKER; DROP TABLE TAXVALUES CASCADE CONSTRAINTS; CREATE TABLE TAXVALUES MaxAmount NUMBERmaximum tax amount TaxRate NUMBERtax rate ; INSERT INTO TAXVALUES VALUES ; SELECT FROM TAXVALUES; COMMIT; Write a script containing just an anonymous PLSQL block that will do the following: First, read the maximum tax amount and tax rate from the TAXVALUES table, store them in variables, and display their values. You may assume that the TAXVALUES table contains exactly one record. Next, for each worker in the CWORKER table, compute the amount of tax to be withheld from their salary, as follows: If the salary times the tax rate is less than the maximum tax amount, then the amount of tax to be withheld is the salary times the tax rate. So for the values in the sample TAXVALUES table, a worker with a salary of would have a tax amount of withheld.If the salary times the tax rate is greater than or equal to the maximum tax amount, then the amount of tax to be withheld is the maximum tax amount. So for the values in the sample TAXVALUES table, a worker with a salary of would have a tax amount of withheld, since exceeds Output each workers information on a single line, showing their ID salary, tax amount, and net pay ie the salary minus the amount of tax withheld Add a to the end of each line in which the maximum tax amount is withheld. Also, compute the total tax withheld from all the workers salaries and report that total at the end. For the sample data given, the output should be: Tax rate: Maximum Tax: : : : : : : : Total tax withheld: Note: Be aware that this is just an example your anonymous PLSQL procedure and trigger should work in general, not just for the given sample data. Part II Triggers Consider the table TAUDIT with attributes WID, OLDSal, NEWSal, NEWTax, auditDate defined and populated by the following script: DROP TABLE TAUDIT CASCADE CONSTRAINTS; CREATE TABLE TAUDIT WID CHAR REFERENCES CWORKERWID OLDSal NUMBER NEWSal NUMBER OLDTax NUMBER NEWTax NUMBER auditDate DATE DEFAULT SYSDATE, PRIMARY KEY WID auditDATE; Write a SQL trigger that will do the following: The trigger should be named NewTaxByLastFirst replace Last and First with your last and first names, respectively. In my case, it should be NewTaxByPerazaEliecer The trigger should be fired after a salary of a worker changes. It only should run for those workers not withholding the maximum tax before the update. It should insert all the information requested in the TAUDIT table for each time the trigger body runs once for each row meeting the condition It should output each workers information on single line, showing their ID old salary, old tax amount, new salary, new tax amount, and difference of tax withheld. The output should look like this: : : : : Note: this output is the result of executing UPDATE CWORKER SET WSalary WSalary; Note: this is the result of running SELECT FROM taudit; after the above UPDATE has run. The tax rate and max amount may be hard coded for the trigger condition but must be retrieved from the taxvalues table when used in the body of the trigger. PLEASE ANSWER PART I AND II I WILL GIVE THUMBS UP
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started