数据库设计——是否尊重第三个NF?

发布于 2024-09-04 18:15:59 字数 308 浏览 11 评论 0原文

我在关系模型中有以下关系(表)

Person
  person_id, first_name, last_name, address

Student
  person_id, matr_nr

Teacher
  person_id, salary

Lecture
  lecture_id, lect_name, lect_description

Attendees
  lecture_id, person_id, date

我想知道学生和教师的功能依赖关系。

这些表符合第三范式吗?这些表的主键应该是哪个?

I have the following relations (tables) in a relational model

Person
  person_id, first_name, last_name, address

Student
  person_id, matr_nr

Teacher
  person_id, salary

Lecture
  lecture_id, lect_name, lect_description

Attendees
  lecture_id, person_id, date

I'm wondering about the functional dependencies of Student and Teacher.

Do these tables respect the 3rd normal form? Which should be the primary keys of these tables?

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

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

发布评论

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

评论(4

转身以后 2024-09-11 18:15:59

使用“表继承”(松散地)和联接表等概念,我会以这种方式进行设置:

 Person
  person_id, first_name, last_name, address

Student
  student_id, person_id, matr_nr

Teacher
  teacher_id, person_id, salary

Lecture
  lecture_id, teacher_id, lect_name, lect_description, date

Attendees
  lecture_id, student_id

其中学生和教师表从人员“继承”,而参加者表是讲座和学生之间的联接表(teacher_id 用于讲座表指定谁在授课。通过连接表最佳实践,该表实际上应命名为 Lecture_Student 或类似名称)

替代设计:(允许一个班级有多名教师)

Person
person_id, first_name, last_name, address

Student
student_id, person_id, matr_nr

Teacher
teacher_id, person_id, salary

Lecture
lecture_id, lect_name, lect_description, date

Lecture_Student
lecture_id, student_id

Lecture_Teacher
lecture_id, teacher_id

Using concepts like "table inheritance" (loosely) and join tables I would set things up in this manner:

 Person
  person_id, first_name, last_name, address

Student
  student_id, person_id, matr_nr

Teacher
  teacher_id, person_id, salary

Lecture
  lecture_id, teacher_id, lect_name, lect_description, date

Attendees
  lecture_id, student_id

Where Student and Teacher tables "inherit" from Person and the Attendees table is a Join table between Lecture and Student (teacher_id is used in the Lecture table to specify who's teaching the class. And by Join table best practice the table ought actually be named Lecture_Student or similar)

Alternate Design: (allows for multiple teachers of a class)

Person
person_id, first_name, last_name, address

Student
student_id, person_id, matr_nr

Teacher
teacher_id, person_id, salary

Lecture
lecture_id, lect_name, lect_description, date

Lecture_Student
lecture_id, student_id

Lecture_Teacher
lecture_id, teacher_id
深海蓝天 2024-09-11 18:15:59

据我们所知,我认为它是 3NF 标准化的(密钥、整个密钥,除了密钥什么都没有),但它可能无法解决您的问题域问题。

您的主键将是 _id 列 - 与会者除外。其中两个 _id 列 - 但这不能适应在不同日期参加同一讲座(或者技术上这会是不同的 Lecture_id 吗?)在我构建的课程安排系统中,我们在班级中有部分,但问题域因为这可能比你所给予的要大得多。

学生和老师的问题已经被提出了 - 两者都将是参加者,这就是你所知道的 - 所有老师都可以在教学,或者只有其中一些可以在教学,或者他们可以是同伴(例如研讨会)

我认为这首先是一个领域建模问题,然后是标准化问题......

I think it's 3NF normalized (the key, the whole key, and nothing but the key) as far as what we know, but it might not solve your problem domain issues.

Your primary keys would be the _id columns - except for attendees. where it would be both _id columns - but this would not accommodate attending the same lecture on different dates (or would that technically be a different lecture_id?) In a class scheduling system I built, we had sections in a class, but the problem domain for this could be much larger than what you have given.

The problem with students and teachers has already been raised - both will be attendees, that's about all you will know - all the teachers could be teaching or only some of them could be teaching, or they could be peers (seminar, say)

I think this is more of a domain modeling issue first, then normalization...

旧人九事 2024-09-11 18:15:59

“这些表遵循第三范式吗?”

只有当您告诉我们键是什么以及完整的函数依赖关系集是什么时,这个问题才可以回答。

如果没有这一点,任何人给出的任何答案都只能是回答者非零猜测的结果,并且您无法保证该猜测符合您的业务现实。

也就是说,您可以查看与会者。那里很可能有什么东西腐烂了。

(嘿,你声称自己不想被灌输。)

"Do these tables respect the 3rd normal form?"

That question is only answerable if you tell us what the keys are and what the full set of functional dependencies is.

Without that, any answer anyone gives can only be the result of a nonzero amount of guesswork on the part of the answerer, and you have no guarantee that that guesswork corresponds to your business reality.

That said, you might look into the Attendees. It's more than likely that there's something rotten there.

(Hey, you claimed yourself you didn't want to be spoonfed.)

我还不会笑 2024-09-11 18:15:59

这绝对不是3NF。上述问题的简单规范化设计(假设 person_id 唯一标识教师和学生,并且每个讲座有一名教师)如下:

Person
  person_id (PK), first_name, last_name, address, Student_matr_nr, Teacher_salary

Lecture
  lecture_id (PK), teacher_person_id (FK), lect_name, lect_description

Attendees
  lecture_id (PK), student_person_id (PK), date

彼此具有相同键的关系是相同的关系

It's definitely not 3NF. A simple, normalised design for the above problem (assuming that person_id uniquely identifies both teachers and students, and that there is one teacher per lecture) would be as follows:

Person
  person_id (PK), first_name, last_name, address, Student_matr_nr, Teacher_salary

Lecture
  lecture_id (PK), teacher_person_id (FK), lect_name, lect_description

Attendees
  lecture_id (PK), student_person_id (PK), date

Relations that have the same key as each other are the same relation.

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