数据库中的建模课程和先决条件
基本场景:我有学生、课程和课程要求需要存储在数据库中。
有人对存储这些内容和遍历课程先决条件的最佳方式有任何见解吗?
1) 简单示例:
- C:数学 100,先决条件:无
- C:数学 150,先决条件:无
- C:数学 200,先决条件:数学 101,数学 150
学生 A 完成了数学 100。如何确定自己是否有资格参加 CS200通过数据库查询?
2)更复杂的示例:
- C:Chem 100,先决条件:无
- C:Chem 200,先决条件:Chem 100
- C:Chem 201,先决条件:Chem 200
- C:Chem 202,先决条件:Chem 200
- C:Chem 300,先决条件:任意两个Chem 200、Chem 201、Chem 202
学生 B 完成了 Chem 100、Chem 200、Chem 203。您如何检查他是否有资格参加 Chem 300?
如何对数据库中的先决条件层次结构进行建模?任何建议、链接、参考都将受到欢迎。
Basic scenario: I have students, courses, and course-requirements that need to be stored in the database.
Anyone has any insight into the best way to store these and traverse course prerequisites?
1) Simple example:
- C: Math 100, prereq: none
- C: Math 150, prereq: none
- C: Math 200, prereq: Math 101, Math 150
Student A completed Math 100. How does one determine if he is eligible to take CS200 via database querying?
2) More complicated example:
- C: Chem 100, prereq: none
- C: Chem 200, prereq: Chem 100
- C: Chem 201, prereq: Chem 200
- C: Chem 202, prereq: Chem 200
- C: Chem 300, prereq: any two of Chem 200, Chem 201, Chem 202
Student B completed Chem 100, Chem 200, Chem 203. How do you check that he is eligible to take Chem 300?
How to model the pre-requisites hierarchy in the database? Any advice, links, references would be most welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有考虑到一些事情,例如需要定义的实体,它们隐含在您的问题中。请允许我包括一些内容,但不要被它们分散注意力,我正在关注您提出的问题。您现在可以放心地忽略
成绩、老师
等,并在未来考虑它们。大学典型数据模型
IDEF1X 表示法, 对于那些需要符号解释的人。
除非需要,否则不需要添加代理键,因为自然键变得太大而无法带入子级中;我并没有在每张桌子上盲目地将它们标记为PK。无论如何,考虑的是物理层面,而不是逻辑层面。
我曾经为当地一所大学建模过 RDb。我认为除了诸如“任何两个......”之类的先决条件之外,您可能还需要“以及至少一个......”,所以我有提供这些的任意组合。
Requisite
包含可能的必备条件的完整列表IsMandatory
标识该先决条件是满足“至少其中一项......”所必需的必备条件;其余的则不是,并且属于“任意两个...”Grade
允许将最低等级指定为必需条件。
Course.NumRequisite
标识可能需要的Requisites
的数量,如“任意两个...”如果您需要 SQL 代码来导航结构,请询问。
There are are few things you have not thought about, as in Entities that need to be defined, that are implicit in your question. Permit me to include a few, but do not get distracted by them, I am focusing on your stated question. You can safely ignore
Grade, Teacher
, etc for now and contemplate them for the future.Typical Data Model for a College
IDEF1X Notation, for those who need explanation of the symbols.
There is no need to add Surrogate keys unless they are required, due the the natural key becoming too large to carry into the children; I have not blindly stamped them as PK on every table. In any case, the consideration is at the physical, not logical level.
I modelled a RDb for a local university once. I think in addition to pre-requisites such as "any two of ...", you may need "and at least one of ...", so I have provided for any combination of those.
Requisite
contains the full list of possible requisitesIsMandatory
identifies that the Requisite is Madatory required to fulfil the "at least one of ..."; the remainder are not, and fall into the "any two of ..."Grade
allows a minimum Grade to be specified as requisite.
Course.NumRequisite
identifies the number, of the possibleRequisites
, that are required, as in "any two of ..."If you need SQL code to navigate the structure, please ask.
我认为以下内容可以满足您的大部分要求:
鉴于上面的查询,检查学生是否已成功完成所有课程作业以参加给定课程,如果编写查询以返回先修课程,实际上会更容易学生没有采取 - 请
注意,这还没有以任何方式进行测试,并且可能包含一些可怕的逻辑错误(例如,我对课程表的后期连接有点怀疑),但它应该很有用作为开始的东西。或者,引用哲学家普拉切特的话
未在动物身上进行测试 - 你将是第一个!
分享并享受。
I think the following would do most of what you want:
Given the above the query to check to see if a student has successfully completed all coursework to take a given class would actually be easier if the query was written to return the pre-requisite courses the student HAD NOT taken - something like
Note that this hasn't been tested in any way and may contain some hideous logic errors (I'm a little leery of the late join of the COURSE table, for instance) but it should be useful as something to get started with. Or, to quote the philosopher Pratchett
Not tested on animals - you'll be the first!
Share and enjoy.