Ask PL-SQL Expert

Assignment: Database Programming

1)

Employees may move to different departments. We want to keep track of the departments where each employee has been. To do so we create a new table emp_dept_change that keeps track of such history.

EMP_DEPT_CHANGE(EMPLOYEE_ID, EMPLOYEE_NAME, OLD_DEPARTMENT_NAME,

                                  NEW_DEPARTMENT_NAME, EFFECTIVE_DATE);Write a trigger emp_dept_change_trg that monitors the employee table as follows.

• When a row (record) is inserted into the employee table, the trigger automatically inserts a row (record) into the emp_dept_change table in any situations.

o The OLD_DEPARTMENT_NAMEis always'[New Hire]'.
o Find the new department name from the departmenttable based on the new department_id.

If the new department_id is NULL, the NEW_DEPARTMENT_NAME will be '[-----]'.

• When an employee changes his/herdepartment (the old department_id is not equal to the new department_id), the trigger automatically inserts a row (record) into the emp_dept_change table. (If both the old department_id and new department_id are NULL (from NULL department to NULL department), the trigger does not insert a row (record) into the emp_dept_change table.)

o Find the old department name from the departmenttable based on the old department_id.
If the olddepartment_id is NULL, the OLD_DEPARTMENT_NAMEwill be '[-----]'.

o Find the new department name from the departmenttable based on the new department_id.
If the new department_id is NULL, the NEW_DEPARTMENT_NAME will be '[-----]'.

• The SYSDATEcan be usedin theEFFECTIVE_DATEcolumn.

• You can assume that the insert/update statements do not violate the integrity constraints between the department and employee tables.

• No temporary table/view/procedure/function is allowed in your trigger.

• You can only use the department, employee, andemp_dept_changetables in your trigger. You will get a zero point if you use a different table (e.g., different table names, column names, or data types) in your trigger.

Step 1) Create the emp_dept_changetable,

CREATE TABLE emp_dept_change

(

EMPLOYEE_ID                                  NUMBER(4)                      NOT NULL,

EMPLOYEE_NAME                             VARCHAR2(50)                 NOT NULL,

OLD_DEPARTMENT_NAME                 VARCHAR2(100)               NOT NULL,

NEW_DEPARTMENT_NAME                VARCHAR2(100)               NOT NULL,

EFFECTIVE_DATE                             DATE                               NOT NULL

);

Step 2) Create the trigger emp_dept_change_trg.

You will get a zero point if you use a different trigger name.

Step 3) Test your trigger.

You need to create/run some test cases to check your trigger. You do not need to submit your test cases.

Q & A)

Q: I keep getting the following prompt when I try to use :OLD and :NEW when doing this week's homework. Does this have to do with my system settings or do I need to enter something on this screen?

125_Snapshoot.jpg

A: You should always click the 2nd button or F5 to run your PL/SQL program. You can find that from lecture note 1, page 8.

2)

Create a trigger called fin_job_min_sal_trg on the employee table. When an INSERT or UPDATE statement is issued against the employee table, the trigger is fired to ensure that the value of the SALARY column meets the criteria in the fin_job_minimum_salarytable in any situations.(For example, you can find that the minimum salary for a programmer is 800 from the fin_job_minimum_salarytable. Your trigger ensures that the salary for a programmer in the employee table is greater than or equal to 800 in any situations.)

Step 1) Create a table fin_job_minimum_salary as follows.

CREATE TABLE fin_job_minimum_salary

(

JOB                           VARCHAR2(50) PRIMARY KEY,

MINIMUM_SALARY       NUMBER(7, 2) NOT NULL

);

Step 2) Populate the fin_job_minimum_salary table as follows.

INSERT INTO fin_job_minimum_salary VALUES ('ANALYST', 2000);

INSERT INTO fin_job_minimum_salary VALUES ('DATABASE ADMINISTRATOR', 2500);

INSERT INTO fin_job_minimum_salary VALUES ('PRESIDENT', 4800);

INSERT INTO fin_job_minimum_salary VALUES ('PROGRAMMER', 800);

INSERT INTO fin_job_minimum_salary VALUES ('PUBLIC ACCOUNTANT', 2400);

INSERT INTO fin_job_minimum_salary VALUES ('SALESMAN', 1800);

INSERT INTO fin_job_minimum_salary VALUES ('VICE PRESIDENT', 3800);

INSERT INTO fin_job_minimum_salary VALUES ('OTHERS', 1800);

COMMIT;

Step 3) Create the trigger fin_job_min_sal_trg.

• The fin_job_minimum_salarytable is read-only. Your trigger cannot modify any rows in the fin_job_minimum_salarytable.

• You must get the minimum salaries from the fin_job_minimum_salarytable in your trigger.

• Thejob is not case sensitive (e.g., SALESMAN = Salesman).

• Hard coding, except the string'OTHERS', is not allowed in your trigger (e.g., IF job = 'SALESMAN' THEN v_min_sal = 1800 ...).

• If the job cannot be found from the fin_job_minimum_salary table(e.g., the job "Program Facilitator" is not in the fin_job_minimum_salary table), the job isconsidered as "OTHERS". (You need to check whetherthe salary is equal to or greater than the minimum salary for job = 'OTHERS'.)

• If the salary is equal to or greater than the minimum salary of the corresponding job, your trigger does not change anything.

• If the salary is less than the minimum salary of the corresponding job, your trigger increases the salary to the minimum salary of the corresponding job.

• No temporary table/view/procedure/function is allowed in your trigger.

• To avoid a mutating table error, please take a look examples on page 8, class handout9. (Hint: you cannot use some INSERT/UPDATE statements to modify the employee table in your trigger.)

• You will get a zero point if you use a different table (e.g., different table names, column names, or data types) in your trigger.

• You will get a zero point if you use a different trigger name.

• If you modified the employee table created in Assignment #1, pleasedelete and re-populate it.

Step 4) Test your trigger.

You need to create/runsome test casesto check whether the values of the salary columnin the employeetable meet the criteria in the fin_job_minimum_salary table in any situations.You do not need to submit your test cases.

Please submit a text file containing all the source codes to D2L before or on due date.

PL-SQL, Programming

  • Category:- PL-SQL
  • Reference No.:- M91924154

Have any Question?


Related Questions in PL-SQL

Complete the following tasksin microsoft access create the

Complete the following tasks: In Microsoft Access, create the database and tables that you identified in W3 Assignment 2. In Microsoft Word, write the SQL statements to create the database and tables. Write SQL statement ...

Purpose of the assessment with ulo mapping the purpose of

Purpose of the assessment (with ULO Mapping) The purpose of this assignment is to develop skills in managing data in databases and to gain understanding of data model development and implementation using a commercially a ...

Continuing the project you have worked on in weeks 1-4 in

Continuing the project you have worked on in Weeks 1-4, in this final week, complete the following tasks: Refine your database and SQL statements by incorporating your instructor's feedback. Verify that the database comp ...

For this assignment you will be provided a database backup

For this assignment, you will be provided a database backup for a database called FinanceDB. You will have to restore this backup to your own version of SQL Server. All of the questions in this assignment relate to the F ...

Assignment - queries functions and triggersaimthe aims of

Assignment - Queries, Functions and Triggers Aim The aims of this assignment are to: formulate SQL queries; populate an RDBMS with a real dataset, and analyse the data; design test data for testing SQL queries; create SQ ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As