我得到的错误是 "外键中的引用列数与引用列数不同,表'StudentGrade'",当试图执行以下SQL脚本时,得到了错误的提示
CREATE TABLE StudentGrade
StudentID INT NOT NULL
CONSTRAINT FK_SG_StudentID FOREIGN KEY (StudentID)
REFERENCES Student(StudentID),
ClassID VARCHAR (6) NOT NULL
CONSTRAINT FK_Class FOREIGN KEY (ClassID, CourseID)
REFERENCES Class(ClassID),
CourseID VARCHAR (64) NOT NULL
CONSTRAINT FK_Course FOREIGN KEY (CourseID)
REFERENCES Course(CourseID),
FacultyID INT NOT NULL
CONSTRAINT FK_Faculty FOREIGN KEY (FacultyID)
REFERENCES Faculty(FacultyID),
Grade NUMERIC NULL,
CONSTRAINT PK_StudentID PRIMARY KEY (StudentID, ClassID, CourseID, FacultyID)
我知道我在外键上做错了什么,但我找不到任何地方解释如何同时使用外键和复合键。 如果有任何帮助,我将不胜感激。 非常感谢您!
将你的第二个外键从
CONSTRAINT FK_Class FOREIGN KEY (ClassID, CourseID)