gpt4 book ai didi

sql-server - 在table 'c_name'上引入FOREIGN KEY constraint 't_name'可能会造成环路或者多级联路径

转载 作者:搜寻专家 更新时间:2023-10-30 19:53:58 24 4
gpt4 key购买 nike

我有一个名为 Lesson 的数据库表:
列: [LessonID, LessonNumber, Description] ...加上一些其他列

我有另一个名为 Lesson_ScoreBasedSelection 的表:
列: [LessonID,NextLessonID_1,NextLessonID_2,NextLessonID_3]

一节课完成后,会在 Lesson_ScoreBasedSelection 表中查找其 LessonID,以获取下一节可能的三节课,每节课都与特定的分数范围相关联。如果分数为 0-33,则将使用存储在 NextLessonID_1 中的 LessonID。如果分数为 34-66,则使用存储在 NextLessonID_2 中的 LessonID,依此类推。

我想用引用类(class)表中 LessonID 列的外键来约束 Lesson_ScoreBasedSelection 表中的所有列,因为 Lesson_ScoreBasedSelection 表中的每个值都必须有一个Lesson 表的 LessonID 列中的条目。我还想打开级联更新,这样如果 Lesson 表中的 LessonID 发生变化,Lesson_ScoreBasedSelection 表中对它的所有引用都会更新。

这个特定的级联更新似乎是一种非常简单的单向更新,但是当我尝试将外键约束应用于引用 Lesson 表中 LessonID 字段的 Lesson_ScoreBasedSelection 表中的每个字段时,我得到错误:

在表“Lesson_ScoreBasedSelection”上引入 FOREIGN KEY 约束“c_name”可能会导致循环或多个级联路径。

谁能解释为什么我会收到此错误或我如何才能实现我描述的约束和级联更新?

最佳答案

您不能有多个级联 RI 链接到任何给定链接表中的单个表。 Microsoft解释这个:

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.

关于sql-server - 在table 'c_name'上引入FOREIGN KEY constraint 't_name'可能会造成环路或者多级联路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7368733/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com