Error message 1785 occurs when you create a FOREIGN KEY constraint that may cause multiple cascade paths (321843)



The information in this article applies to:

  • Microsoft SQL Server 2000 Standard Edition
  • Microsoft SQL Server 2000 Developer Edition
  • Microsoft SQL Server 2000 Enterprise Edition
  • Microsoft SQL Server 2000 Personal Edition
  • Microsoft SQL Server 2000 Desktop Engine (MSDE)
  • Microsoft SQL Server 2005 Standard Edition
  • Microsoft SQL Server 2005 Developer Edition
  • Microsoft SQL Server 2005 Enterprise Edition
  • Microsoft SQL Server 2005 Express Edition
  • Microsoft SQL Server 2005 Workgroup

This article was previously published under Q321843

SYMPTOMS

You may receive the following error message when you create a FOREIGN KEY constraint:
Server: Msg 1785, Level 16, State 1, Line 1 Introducing FOREIGN KEY constraint 'fk_two' on table 'table2' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Server: Msg 1750, Level 16, State 1, Line 1 Could not create constraint. See previous errors.

CAUSE

You receive this error message because in SQL Server, a table cannot appear more than one time in a list of all the cascading referential actions that are started by either a DELETE or an UPDATE statement. For example, the tree of cascading referential actions must only have one path to a particular table on the cascading referential actions tree.

WORKAROUND

To work around this problem, do not create a foreign key that will create more than one path to a table in a list of cascading referential actions.

You can enforce referential integrity in several ways. Declarative Referential Integrity (DRI) is the most basic way, but it is also the least flexible way. If you need more flexibility, but you still want a high degree of integrity, you can use triggers instead.

MORE INFORMATION

The following sample code is an example of a FOREIGN KEY creation attempt that generates the error message:

Use tempdb
go
create table table1 (user_ID integer not null primary key, user_name
char(50) not null)
go

create table table2 (author_ID integer not null primary key, author_name
char(50) not null, lastModifiedBy integer not null, addedby integer not
null)

go

alter table table2 add constraint fk_one foreign key (lastModifiedby)
references table1 (user_ID) on delete cascade on update cascade
go
alter table table2 add constraint fk_two foreign key (addedby)
references table1(user_ID) on delete no action on update cascade
go
--this fails with the error because it provides a second cascading path to table2.

alter table table2 add constraint fk_two foreign key (addedby)
references table1 (user_ID) on delete no action on update no action
go
-- this works.
				

REFERENCES

For more information, please see the "Cascading Referential Integrity Constraints" topic in SQL Server 2000 Books Online.

Modification Type:MinorLast Reviewed:1/24/2006
Keywords:kbBug kbpending kbprb kbProgramming KB321843 kbAudDeveloper