简体   繁体   English

如何检查3NF?

[英]How to check for 3NF?

I have created a simple CRUD application database schehme. 我创建了一个简单的CRUD应用程序数据库schehme。 However, before implementing it I want to check if it is in 3NF : 但是,在实现它之前,我要检查它是否在3NF

CREATE TABLE person (
person_id int not null,
name char(30) not null,
student_no int,
staff_no int,
student_fieldOfStudy char(30),
staff_department char(30),
staff_position char(30),
faculty char(30),
PRIMARY KEY (person_id),
CONSTRAINT student_unique UNIQUE (student_no),
CONSTRAINT staff_unique UNIQUE (staff_no)
);

CREATE TABLE university (
university_id int not null,
foundationDate datetime not null,
university_name char(30) not null,
city_name char(30) not null,
country_name char(30) nut null,
PRIMARY KEY (universityID),
CONSTRAINT univ_unique UNIQUE (university_name, city_name)
);

CREATE TABLE course (
course_id int not null,
course_code char(20) not null,
lecturer_name char(30) not null,
lecture_day datetime not null,
faculty char(30) not null,
lecture_room char(30),
lecturer_id int,
student_id int,
FOREIGN KEY (student_id) REFERENCES Persons(person_id),
FOREIGN KEY (lecturer_id) REFERENCES Persons(person_id)
)

From my opinion it is in 3NF . 我认为这是在3NF I would appreciate your reply! 多谢您的回覆!

It's difficult to comment on a database design without knowing what business rules are supposed to be in force. 如果不知道应该执行哪些业务规则,就很难对数据库设计发表评论。 You need to determine that from your own analysis of the business domain. 您需要根据自己对业务领域的分析来确定。 Without that information all we can do is make some assumptions and guesses based on a list of table and column names. 没有这些信息,我们所能做的就是基于表名和列名的列表做出一些假设和猜测。

The person table looks problematic. 人员表看起来有问题。 Are the student and staff columns supposed to be nullabale? 学生和工作人员专栏是否应该为nullabale? It looks to me like you are maintaining two distinct types of person in one table. 在我看来,您正在一张桌子中维护两种不同类型的人。 Probably better to create distinct tables for each of those person subtypes and just have the attributes that are common to both student and staff in the person table. 为每个人子类型创建不同的表可能更好,并且在人表中仅具有学生和职员共同的属性。

The concept of 3NF is based on relations and dependencies which permit only values, never nulls. 3NF的概念基于关系和依赖关系,这些关系和依赖关系仅允许值,不允许为空。 If you have nulls then you don't have a relation that satisfies 3NF. 如果您有null,那么您就没有满足3NF的关系。 Further, if staff_no is supposed to be a determinant for the staff attributes then it is a non-key determinant (because it's nullable). 此外,如果将staff_no假定为staff属性的决定因素,则它是非关键决定因素(因为它可以为空)。 Nullable uniqueness constraints are a bad idea for multiple reasons and you should try to avoid them. 可空的唯一性约束由于多种原因是个坏主意,您应该尝试避免使用它们。

From a very short glimpse, the course table looks VERY non-3NF. 从很短的时间看,课程表看起来非常非3NF。

  • It lacks a key 缺少钥匙
  • Unless there is only one course per lecturer, then lecturer_id is not the key, so lecturer_name shouldn't be there 除非每个讲师只有一门课程,否则讲者ID不是关键,因此讲师名称不应该存在
  • I guess there can be more than one student per course as well; 我想每门课程也可以有一个以上的学生。 in that case, student_id belongs somewhere else 在这种情况下,student_id属于其他地方
  • Does a lecture room belong to one and only one faculty? 演讲室是否属于一个且只有一个系?
  • Isn't course_code dependent on course_id? course_code是否不取决于course_id?

Just to get you started... 只是为了让您入门...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM