课程先决条件的数据库设计

发布于 2024-10-01 10:33:18 字数 309 浏览 1 评论 0原文

我目前正在开发一个示例课程注册系统,我需要维护该系统的课程先决条件。我必须在页面上将类先决条件显示为布尔表达式。 例子: 如果学生正在查看 A 类,则先决条件必须显示为 (B 和 C) 或 D

我不知道如何处理这个问题。

到目前为止的设计: 一个类有很多部分。 Class(*deptartment, class_number*, description)

斜体是主键。有什么建议如何处理先决条件吗?

课程数据示例: (CMSC,201,编程1) (CMSC,202,编程2) (CMSC,203,离散结构) (CMSC,341,数据结构)

I am currently working on a sample class registration system for which I need to maintain class prerequisites. I have to display class prerequisites on page as a boolean expression.
Example:
If a student is viewing Class A, prerequisites must be displayed as (B AND C) OR D

I am not sure how to handle this.

Design so far:
A Class have many sections.
Class(*deptartment, class_number*, description)

Italics are primary keys. Any suggestions how to handle prerequisites??

Example data for course:
(CMSC,201,Programming 1)
(CMSC,202,Programming 2)
(CMSC,203,Discrete Structures)
(CMSC,341,Data Structures)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

潇烟暮雨 2024-10-08 10:33:18

要添加达菲莫的一对多关系建议,请向该关系添加分组。组 ID 将是您的括号。因此,您的表可能如下所示:

class_id, prereq_group, prereq_id
1, 1, B
1, 1, C
1, 2, D

prereq_group 只需在 class_id 中唯一,并且可以是连续的数字。如果 prereqs 具有相同的组 id,那么它们将是 AND。不同的组 ID 将是一个 OR。因此,在上面的示例中,它将是 (B AND C) OR (D)。

To add to duffymo's suggestion of a one-to-many relationship, add grouping to that relation. The group ID would then be your parenthesis. So your table may look like this:

class_id, prereq_group, prereq_id
1, 1, B
1, 1, C
1, 2, D

The prereq_group only needs to be unique within the class_id and could be a sequential number. If prereqs have the same group id, then they would be AND. Different group ids would be an OR. So in the above example, it would be (B AND C) OR (D).

旧情勿念 2024-10-08 10:33:18

该部分与先决条件无关。

听起来像是一对多的关系。

我不确定通过成绩是否需要成为您的先决条件的一部分。如果是,您还有更多工作要做,因为您需要 Student 和 ReportCard 表来管理先决条件。

Section is irrelevant for prerequisites.

It sounds like a one-to-many relationship.

I'm not sure if a passing grade needs to be part of your prerequisites. If yes, you've got more work to do, because you'll need Student and ReportCard tables to manage Prerequisites.

月下客 2024-10-08 10:33:18

看起来像一个不平凡的设计案例......就 iv 所看到的数据库设计而言,不可能有单一的连接条件而不丢失 1NF。

一个建议的解决方案,可以在不丢失 1NF 的情况下遇到多个自连接 -

假设按班级你的意思是课程......
先决条件(precession_id(pk),class_no*(fk),relation,Linked_Precessions(fk)*)

如果 Linked_Precessions 为 null,我们可以继续使用特定 class_no 下的所有可用行来查找所有先决条件。

例如,

Prerequisites(prerequisite_id,class_with_prerequisite,class_id_of_prerequisite, relationship, linked_prerequisites)
1,1,2,and,2
2,1,3,null,null
3,1,4,or,null

--------------

Class(*deptartment, class_number*(pk), description) 
12,1,classA
12,2,classB
12,3,ClassC
12,4,ClassD
--------------

使用它您可以创建一个有向图。最初,您可以从先决条件中选择数据,使其具有非空数据,然后将其与其自身连接以在其内部创建层次结构。

如果您自己维护数据,您可以操纵它在单级有向图中工作,您只需编写一个一级连接。

Seems like a non trivial design case...As far as iv seen DB designs there can be no single join condition without losing 1NF on this.

A suggested solution which can run into multi self joins without losing 1NF-

Assuming by class u mean course...
prerequisites(prerequisite_id(pk),class_no*(fk),relationship,Linked_Prerequisites(fk)*)

if Linked_Prerequisites is null we can go on using to club all rows available under a particular class_no to find all prerequisites.

eg

Prerequisites(prerequisite_id,class_with_prerequisite,class_id_of_prerequisite, relationship, linked_prerequisites)
1,1,2,and,2
2,1,3,null,null
3,1,4,or,null

--------------

Class(*deptartment, class_number*(pk), description) 
12,1,classA
12,2,classB
12,3,ClassC
12,4,ClassD
--------------

Using this you can create a directed graph. Initially u can select data from prerequisites such that they have non null data and then join it with itself to create a hierarchy within itself.

If you maintain the data yourself u can manipulate this to work at a single level directed graph with which u will have to write just a one level join.

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