我编写了这个触发器,它监视一个名为 employees 的表,当从该表中删除一个员工时,触发器应该触发,并复制我们要从表中删除的员工 employees 并放入另一个名为 deleted_employees 的表中,但是当我把以下sql 语句 delete from employees where employee_id = 100 SQL 错误说:
Error starting at line 17 in command:
delete from employees where employee_id = 100
Error report:
SQL Error: ORA-02292: integrity constraint (HR.DEPT_MGR_FK) violated - child
record found
02292. 00000 - "integrity constraint (%s.%s) violated - child record found"
*Cause: attempted to delete a parent key value that had a foreign
dependency.
*Action: delete dependencies first then parent or disable constraint.
CREATE OR REPLACE TRIGGER EMPLOYEE_DELETED
BEFORE DELETE ON EMPLOYEES
DECLARE
CURSOR CUR_EMP IS
SELECT EMPLOYEE_ID , FIRST_NAME , LAST_NAME , EMAIL ,
PHONE_NUMBER , HIRE_DATE , JOB_ID , SALARY ,
COMMISSION_PCT , MANAGER_ID , DEPARTMENT_ID
FROM EMPLOYEES;
EMP_REC CUR_EMP%ROWTYPE;
BEGIN
OPEN CUR_EMP;
while(CUR_EMP%FOUND) LOOP
FETCH CUR_EMP INTO EMP_REC;
INSERT INTO deleted_employees
(EMPLOYEE_ID , FIRST_NAME , LAST_NAME ,
EMAIL ,
PHONE_NUMBER , HIRE_DATE ,job_id , salary ,
COMMISSION_PCT , MANAGER_ID , DEPARTMENT_ID)
VALUES
(EMP_REC.EMPLOYEE_ID ,EMP_REC.FIRST_NAME ,EMP_REC.LAST_NAME ,
EMP_REC.EMAIL , EMP_REC.PHONE_NUMBER , EMP_REC.HIRE_DATE ,
EMP_REC.JOB_ID , EMP_REC.SALARY , EMP_REC.COMMISSION_PCT ,
EMP_REC.MANAGER_ID , EMP_REC.DEPARTMENT_ID);
END LOOP;
CLOSE CUR_EMP;
END;
我不知道如何测试触发器,有什么想法吗?!