Thursday, December 17, 2009

Violating Constraints

Query :
  • UPDATE emp SET department_id = 29 WHERE department_id = 30;
Error :
  • insert or update on table "emp" violates foreign key constraint "emp_ref_dept_fk"
DETAIL :
  • Key (deptno)=(29) is not present in table "dept"
  • Department 29 does not exist
You cannot delete a row that contains a primary key that is used as a foreign key in another table.

Query :
  • DELETE FROM departments WHERE department_id = 60;
Error :
  • update or delete on table "dept" violates foreign key constraint "emp_re f_dept_fk" on table "emp";
Detail :
  • Key (deptno)=(10) is still referenced from table "emp".

No comments:

Post a Comment

Followers