[英]SQL Error: ORA-02270: no matching unique or primary key for this column-list
[英]Need assistance SQL error (ORA-02270) : no matching unique or primary key for this column-list error
我有多個桌子,
-學生(StudentID [pk],StudentName)
合格(FID [pk],CourseID [pk],dateQ)
-教師(FID [pk],Fname)
-Course(CourseID [pk],CourseName)
我需要再創建2個,分別是Section和Registration。
-Section(SectionNo [pk],Semester [pk],CourseID [pk])
-注冊(StudentID [pk],SectionNo [pk],學期[pk])
我首先創建沒有任何問題的部分:
create table section(
SectionNo number(28) not null,
Semester varchar(25) not null,
CourseID varchar(25) not null,
constraint sec_pk primary key(SectionNo,Semester,CourseID),
constraint sec_fk foreign key(CourseID) references Course(CourseID)
on delete cascade);
然后,我嘗試制作一個名為registration的表,但這給了我標題錯誤。
create table registration(
StudentID number(28) not null,
SectionNo number(28) not null,
Semester varchar(25) not null,
constraint reg_pk primary key(SectionNo,StudentID,Semester),
constraint reg_fk foreign key(StudentID) references Student(StudentID)
on delete cascade,
constraint reg_fk2 foreign key(SectionNo,Semester) references
Section(SectionNo,Semester) on delete cascade);
有人可以幫我找出問題所在嗎?
ORA-2270錯誤非常簡單:當我們在外鍵中引用的列與主表上的主鍵或唯一約束不匹配時,就會發生此錯誤。
在這里,根據您的情況,節表的主鍵是(SectionNo,Semester,CourseID),而您僅引用Section(SectionNo,Semester)
要擺脫這種情況,請在您的輔助密鑰中也添加“ CourseID
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.