Hi!
For the sake of simplicity, I have three tables, Employee, Department and
Work
Employee >---- Department
\ /
\ /
^ ^
Work
The Work table have two columns, empno and depno and consists that the
employee has worked on another department.
Here is my scripts:
create table employee (empno int not null primary key, depno int not null)
create table department (depno int not null primary key)
create table work (empno int not null, depno int not null)
alter table employee add constraint fk_employee_dep artment foreign key
(depno)
references department (depno)
on update cascade
alter table work add constraint fk_work_employe e foreign key (empno)
references employee (empno)
on update cascade
alter table work add constraint fk_work_departm ent foreign key (depno)
references department (depno)
on update cascade
My problem is the last command. SQL Server responds:
Server: Msg 1785, Level 16, State 1, Line 1
Introducing FOREIGN KEY constraint 'fk_work_depart ment' on table 'work' may
cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON
UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
But I want the depno in the work table to be updated when a department.depn o
changes a value.
Does anyone have a suggestion on how to overcome this problem?
Thanks in advance
Best regards,
Gunnar Vøyenli
EDB-konsulent as
NORWAY