Introducing FOREIGN KEY constraint 'c_name' on table 't_name' may cause cycles or multiple cascade paths

前端 未结 2 1935
走了就别回头了
走了就别回头了 2020-12-22 11:07

I have a database table called Lesson:
columns: [LessonID, LessonNumber, Description] ...plus some other columns

I hav

相关标签:
2条回答
  • 2020-12-22 11:35

    Given the SQL Server constraint on this, why don't you solve this problem by creating a table with SelectionID (PK), LessonID, Next_LessonID, QualifyingScore as the columns. Use a constraint to ensure LessonID and QualifyingScore are unique.

    In the QualifyingScore column, I'd use a tinyint, and make it 0, 1, or 2. That, or you could do a QualifyingMinScore and QualifyingMaxScore column so you could say,

    SELECT * FROM NextLesson 
    WHERE LessonID = @MyLesson 
    AND QualifyingMinScore <= @MyScore 
    AND @MyScore <= QualifyingMaxScore
    

    Cheers,
    Eric

    0 讨论(0)
  • 2020-12-22 11:52

    You can't have more than one cascading RI link to a single table in any given linked table. Microsoft explains this:

    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.

    0 讨论(0)
提交回复
热议问题