外键约束可能导致循环或多个级联路径 [英] Foreign Key Constraints may cause cycles or multiple cascade paths

查看:27
本文介绍了外键约束可能导致循环或多个级联路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
外键约束可能导致循环或多个级联路径?

创建下表时出现以下错误.

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

消息 1785,第 16 级,状态 0,第 1 行在表Faculty"上引入 FOREIGN KEY 约束FKFacSupervisor"可能会导致循环或多个级联路径.指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束.消息 1750,第 16 级,状态 0,第 1 行无法创建约束.查看以前的错误.

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
)

推荐答案

消息告诉您无法创建外键约束 FKFacSupervisor,因为此约束可能导致循环或多个级联路径.这意味着约束可能导致对一行的更新或删除可能导致对另一行的更新或删除,这反过来又可能导致对第一行的更新或删除.该消息还解释了可能的解决方案:指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他约束.只有了解架构和预期的使用模式,您才能决定哪些选项是最好的.

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.

这篇关于外键约束可能导致循环或多个级联路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆