表定义:
Student(StudentID, StudentName) PK StudentID
Faculty(FacultyID, FacultyName) PK FacultyID
Course(CourseID, CourseName) PK CourseID
Qualified(FacultyID, CourseID, DateQualified) PK FacultyID CourseID
Section(SectionNo,Semester, CourseID) PK SectionNo Semester CourseID
Registration(StudentID, SectionNo, Semester) PK StudentID SectionNo Semester如何链接表注册和区段?StudentID在注册作为外键引用来自StudentID的学生表,但我能做什么与SectionNo和学期?我可以在外键Section_Semester (SectionNo,学期)上添加一个约束,但是这两个属性在节表中并不是唯一的。在区段表中添加对主键的约束?
谢谢
发布于 2015-04-17 22:04:49
如果我正确地理解了您的意思,您是说您的区段表有一个主键( sectionNo,there,courseID),因此可以使用相同的sectionNo和there来记录多个记录?然后要将没有courseID的注册连接到这个表中?据我所知,您不能使用“引用”子句,因为它不会链接到唯一标识符。但这并不能阻止您编写连接这两个表的查询。
更新
当然,有许多可能的查询取决于您想知道的是什么。比方说,如果你想知道第17名学生注册的所有课程,你可以这样写:
select section.sectionno, section.semester, section.courseid
from registration
join section on section.sectionno=registration.sectionno
and section.semester=registration.semester
where studentid=17如果您希望在给定的注册记录中提供所有课程:
select coursed
from registration
join section on section.sectionno=registration.sectionno
and section.semester=registration.semester
where registration.sectionno=@section
and registration.semester=@semester
and registration.studentid=@student现在,嗯,写这个问题,这向我表明,一个学生注册的所有课程组成了一个部分和学期。这是真的吗?如果一节和一学期有多门课程,学生是同时报名参加所有课程,还是选择个别课程?如果他选择了,那么注册似乎需要指定哪一门课程。
我不知道“段”在这里是什么意思,所以我不知道它是怎么联系的。
发布于 2015-04-20 01:10:35
我看不出没有CourseID你怎么能有一个完整的注册元组。如果SectionNo和学期的组合不是唯一的,那么学生注册了什么?本学期所有指定的章节?不,他们注册了一个特定的课程(在指定的时间在指定的地点举行会议)。
当然,我不知道科室代表了什么。但无论它代表了什么,它显然不具备缩小学生注册范围的粒度。你得把这个包括进去。
https://stackoverflow.com/questions/29690161
复制相似问题