mysticmoonlight
11-24-2005, 04:06 PM
1. (Trigger) LogEmpChange
(a) Create a table called EmpAudit that keeps track of all the changes made to Salary, SuperSSN, and DNO of EMPLOYEE table as follows: (4)
EmpAudit ( AuditSeqID NUMBER(5) PRIMARY KEY,
Emp_ID NUMBER(4) NOT NULL,
Change_Type CHAR(1) NOT NULL, -- one of I/U/D
Changed_By VARCHAR2(10),
Time_Stamp DATE NOT NULL,
Old_Salary NUMBER(10),
Old_Mgr_ID NUMBER(4)
Old_job_code NUMBER(2)
New_Salary NUMBER(10),
New_MgrID NUMBER(4),
New_job_code NUMBER(2) );
• Emp_ID represents the person whose data is changed.
• Create a unique sequence for AuditSeqID beginning from 00001 (use CREATE SEQUENCE statement). Increase the value of AuditSeqID by 1 automatically for every insertion.
• Changed_By will store the user name who updated the table. Use the pseudo column name called USER to determine the value to store in Changed_by. USER is a pseudo column pre-defined in Oracle.
• For Change_Type, use "I" for Insert, "D" for Delete, and "U" for Update commands. Define the valid Change_Type using CHECK clause in CREATE command.
• Time_Stamp attribute must enter/display date of the change.
(b) Create a trigger called LogEmpChange (with proper naming convention discussed in the lecture note) that writes every meaningful change against EMPLOYEE table into EmpAudit table as shown above. Note that for update case, you have to add a record to EmpAudit only when the audited attribute is changed. For deletion case, you have to add a record with the deleted value of those audited attributes. (10)
(c) Do the following sequence of updates for testing your trigger. (3)
- Insert John Doe with emp_ID = 9999 and manager_ID = 7508 and other arbitrary data
- Increase the salary of LYNN DENNIS into $5000.
- Change the commission of JEAN KELLY into 10% of her salary
- Change the job code of CYNTHIA WARD into 40.
- Delete (with cascade option) John Doe
(a) Create a table called EmpAudit that keeps track of all the changes made to Salary, SuperSSN, and DNO of EMPLOYEE table as follows: (4)
EmpAudit ( AuditSeqID NUMBER(5) PRIMARY KEY,
Emp_ID NUMBER(4) NOT NULL,
Change_Type CHAR(1) NOT NULL, -- one of I/U/D
Changed_By VARCHAR2(10),
Time_Stamp DATE NOT NULL,
Old_Salary NUMBER(10),
Old_Mgr_ID NUMBER(4)
Old_job_code NUMBER(2)
New_Salary NUMBER(10),
New_MgrID NUMBER(4),
New_job_code NUMBER(2) );
• Emp_ID represents the person whose data is changed.
• Create a unique sequence for AuditSeqID beginning from 00001 (use CREATE SEQUENCE statement). Increase the value of AuditSeqID by 1 automatically for every insertion.
• Changed_By will store the user name who updated the table. Use the pseudo column name called USER to determine the value to store in Changed_by. USER is a pseudo column pre-defined in Oracle.
• For Change_Type, use "I" for Insert, "D" for Delete, and "U" for Update commands. Define the valid Change_Type using CHECK clause in CREATE command.
• Time_Stamp attribute must enter/display date of the change.
(b) Create a trigger called LogEmpChange (with proper naming convention discussed in the lecture note) that writes every meaningful change against EMPLOYEE table into EmpAudit table as shown above. Note that for update case, you have to add a record to EmpAudit only when the audited attribute is changed. For deletion case, you have to add a record with the deleted value of those audited attributes. (10)
(c) Do the following sequence of updates for testing your trigger. (3)
- Insert John Doe with emp_ID = 9999 and manager_ID = 7508 and other arbitrary data
- Increase the salary of LYNN DENNIS into $5000.
- Change the commission of JEAN KELLY into 10% of her salary
- Change the job code of CYNTHIA WARD into 40.
- Delete (with cascade option) John Doe