可能重复:
Foreign key constraint may cause cycles or multiple cascade paths?
创建下面列出的表时出现以下错误。
Msg 1785,Level 16,State 0,Line 1 在表'Faculty'上引入FOREIGN KEY约束'FKFacSupervisor'可能会导致循环或多个级联路径。指定ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他FOREIGN KEY约束。 Msg 1750,Level 16,State 0,Line 1 无法创建约束。查看以前的错误。
CREATE TABLE Faculty
(
FacNo CHAR (11),
FacFirstName VARCHAR (50)CONSTRAINT FacFirstNameRequired NOT NULL,
FacLastName VARCHAR (50) CONSTRAINT FacLastNameRequired NOT NULL,
FacCity VARCHAR (50) CONSTRAINT FacCityRequired NOT NULL,
FacState CHAR (2) CONSTRAINT FacStateRequired NOT NULL,
FacZipCode CHAR (10) CONSTRAINT FacZipCodeRequired NOT NULL,
FacHireDate DATE,
FacDept CHAR (6),
FacRank CHAR (4),
FacSalary DECIMAL (10,2),
FacSupervisor CHAR (11),
CONSTRAINT PKFaculty PRIMARY KEY (FacNo),
CONSTRAINT FKFacSupervisor FOREIGN KEY (FacSupervisor) REFERENCES Faculty
ON DELETE SET NULL
ON UPDATE CASCADE
)
答案 0 :(得分:0)
该消息告诉您无法创建外键约束FKFacSupervisor,因为此约束可能导致循环或多个级联路径。这意味着约束可能导致更新或删除一行可能导致更新或删除另一行的情况,这可能反过来导致更新或删除第一行。该消息还说明了可能的解决方案:指定ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他约束。只有了解架构和预期的使用模式,才能确定哪些选项最佳。