sql - 如何创建具有多年历史的学校数据库?
问题描述
我正在制作一个模拟学校数据库,我在纸上有一个基本模型,但是当我考虑不同的日期以及如何创建学期/季度甚至年份之间的关系时,事情变得非常复杂,因为这样做没有意义在我的班级表中具有相同的班级,但日期不同。这会令人困惑,对吗?我对我的问题进行了快速的谷歌搜索,主要是为我的数据库找到了一种称为日期维度的方法。甚至不确定这是否是我需要的。
几乎我想要的只是组织/设置我的表之间的关系以存储多年的相似数据,即:具有相同 id 但日期不同的班级,不同的学生,仅在我需要特定年份或如果需要,所有年份。
ATM 我的架构是这样的。
students --table with all students
------------
student_id serial
first_name varchar(20)
last_name archer(20)
class -- bridge table
------------
class_id integer
class_name text
student_id integer
grade varchar(2)
classes --table with all classes
------------
class_id serial
dept_id integer
class_name text
student_history --bridge table with a calander?
------------------
class_id integer
class_name text
grade varchar(2)
解决方案
我会这样:
-- this holds the students
create table student (id, name);
-- this holds the courses (for example, "Intro to CS", which is
-- offered every year)
create table course (id, department_id, name);
-- this table shows what studends took which courses in which
-- semesters, and what grade they got. Because you have this, you
-- don't need a history table
create table enrollment (student_id, course_id, semester, grade)
如果您想存储诸如“谁教课”之类的内容,它可能会变得更加复杂,但这可以解决您的迫切需求。
推荐阅读
- reactjs - 为什么我的 usestate 挂钩值在 onClick 事件之后没有更新而完全没有错误?
- java - 计算复多项式的值
- python - 如何有效地在 Scipy 中生成正常的随机变量 >= 零?
- php - 尝试通过 Laravel 中的一对多关系输出文件名
- html - CSS 格式化一个元素到外面但仍然与父 div 相关
- javascript - 如何处理多个相同的 fetch 请求?
- visual-studio-code - 如何在 VSCode 中的 npm 任务上设置打字稿问题匹配器?
- javascript - ASP.Net MVC 在发布后找不到我的 JS 文件之一
- amazon-web-services - “未授权”读取由 EC2 Instance Scheduler 云形成模板创建的 DynamoDB 表
- python - 将 ElementTree 转换为字符串会从输出中去除 CDATA 部分