且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

外键约束可能会导致周期或多个级联路径

更新时间:2023-02-03 07:54:14

消息告诉你在您的外键约束FKFacSupervisor不能被创建,因为这个约束可能会导致周期或多个级联路径。这意味着约束可能会导致更新或删除一行可能会导致更新或删除到另一行,这可能会导致更新或删除到第一行的情况。该消息还解释了可能的解决方案:指定ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他约束。只有了解架构和预期的使用模式,才能决定哪些选项是***的。


Possible Duplicate:
Foreign key constraint may cause cycles or multiple cascade paths?

I am getting the following error while creating the table listed below.

Msg 1785, Level 16, State 0, Line 1 Introducing FOREIGN KEY constraint 'FKFacSupervisor' on table 'Faculty' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Msg 1750, Level 16, State 0, Line 1 Could not create constraint. See previous errors.

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
)

The message is telling you that your foreign key constraint FKFacSupervisor cannot be created because this constraint could cause cycles or multiple cascade paths. That means that the constraint could result in a situation where updates or deletes to one row could cause updates or deletes to another row, which could in turn cause updates or deletes to the first row. The message also explains possible solutions: Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other constraints. Only by knowing the schema and the expected usage patterns can you decide which of those options will be best.