数据库中的建模课程和先决条件

发布于 2024-10-01 19:51:26 字数 577 浏览 0 评论 0原文

基本场景:我有学生、课程和课程要求需要存储在数据库中。

有人对存储这些内容和遍历课程先决条件的最佳方式有任何见解吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凑诗 2024-10-08 19:51:26

您没有考虑到一些事情,例如需要定义的实体,它们隐含在您的问题中。请允许我包括一些内容,但不要被它们分散注意力,我正在关注您提出的问题。您现在可以放心地忽略成绩、老师等,并在未来考虑它们。

大学典型数据模型

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 requisites

    • IsMandatory 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 possible Requisites, that are required, as in "any two of ..."

If you need SQL code to navigate the structure, please ask.

爱的那么颓废 2024-10-08 19:51:26

我认为以下内容可以满足您的大部分要求:

Table COURSE
  ID_COURSE    NUMBER         PRIMARY KEY
  DESCRIPTION  VARCHAR2(200)

Table PREREQUISITE_COURSE
  ID_COURSE         NUMBER    REFERENCES COURSE.ID_COURSE
  ID_PREREQ_COURSE  NUMBER    REFERENCES COURSE.ID_COURSE
  PRIMARY KEY (ID_COURSE, ID_PREREQ_COURSE)

Table STUDENT
  ID_STUDENT        NUMBER    PRIMARY KEY

Table STUDENT_COURSE
  ID_STUDENT        NUMBER    REFERENCES STUDENT.ID_STUDENT
  ID_COURSE         NUMBER    REFERENCES COURSE.ID_COURSE
  COMPLETED         CHAR(1)   CHECK(IN('Y', 'N'))
  PASSED            CHAR(1)   CHECK(IS NULL OR IN ('Y', 'N'))

鉴于上面的查询,检查学生是否已成功完成所有课程作业以参加给定课程,如果编写查询以返回先修课程,实际上会更容易学生没有采取 - 请

SELECT c.*
  FROM STUDENT s
INNER JOIN COURSE STUDENT_COURSE sc
  ON (sc.ID_STUDENT = s.ID_STUDENT)
LEFT OUTER JOIN PREREQUISITE_COURSE pc
  ON (pc.ID_PREREQ_COURSE = sc.ID_COURSE)
INNER JOIN COURSE c
  ON (c.ID_COURSE = pc.ID_COURSE)
WHERE s.ID_STUDENT = <id of student of interest> AND
      c.ID_COURSE = <id of course of interest> AND
      sc.COMPLETED = 'Y' AND
      sc.PASSED = 'Y' AND
      pc.ID_PREREQ_COURSE IS NULL

注意,这还没有以任何方式进行测试,并且可能包含一些可怕的逻辑错误(例如,我对课程表的后期连接有点怀疑),但它应该很有用作为开始的东西。或者,引用哲学家普拉切特的话

未在动物身上进行测试 - 你将是第一个!

分享并享受。

I think the following would do most of what you want:

Table COURSE
  ID_COURSE    NUMBER         PRIMARY KEY
  DESCRIPTION  VARCHAR2(200)

Table PREREQUISITE_COURSE
  ID_COURSE         NUMBER    REFERENCES COURSE.ID_COURSE
  ID_PREREQ_COURSE  NUMBER    REFERENCES COURSE.ID_COURSE
  PRIMARY KEY (ID_COURSE, ID_PREREQ_COURSE)

Table STUDENT
  ID_STUDENT        NUMBER    PRIMARY KEY

Table STUDENT_COURSE
  ID_STUDENT        NUMBER    REFERENCES STUDENT.ID_STUDENT
  ID_COURSE         NUMBER    REFERENCES COURSE.ID_COURSE
  COMPLETED         CHAR(1)   CHECK(IN('Y', 'N'))
  PASSED            CHAR(1)   CHECK(IS NULL OR IN ('Y', 'N'))

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

SELECT c.*
  FROM STUDENT s
INNER JOIN COURSE STUDENT_COURSE sc
  ON (sc.ID_STUDENT = s.ID_STUDENT)
LEFT OUTER JOIN PREREQUISITE_COURSE pc
  ON (pc.ID_PREREQ_COURSE = sc.ID_COURSE)
INNER JOIN COURSE c
  ON (c.ID_COURSE = pc.ID_COURSE)
WHERE s.ID_STUDENT = <id of student of interest> AND
      c.ID_COURSE = <id of course of interest> AND
      sc.COMPLETED = 'Y' AND
      sc.PASSED = 'Y' AND
      pc.ID_PREREQ_COURSE IS NULL

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文