简体   繁体   English

这些表是否符合3NF数据库规范化?

[英]Are these tables respect the 3NF Database Normalization?

AUTHOR table AUTHOR

  • Author_ID , PK Author_ID ,PK
  • First_Name
  • Last_Name

TITLES table TITLES

  • TITLE_ID , PK TITLE_ID ,PK
  • NAME
  • Author_ID , FK Author_ID ,FK

DOMAIN table DOMAIN

  • DOMAIN_ID , PK DOMAIN_ID ,PK
  • NAME
  • TITLE_ID , FK TITLE_ID ,FK

READERS table READERS

  • READER_ID , PK READER_ID ,PK
  • First_Name
  • Last_Name
  • ADDRESS
  • CITY_ID , FK CITY_ID ,FK
  • PHONE

CITY table CITY

  • CITY_ID , PK CITY_ID ,PK
  • NAME

BORROWING table BORROWING

  • BORROWING_ID ,pk BORROWING_ID ,pk
  • READER_ID , fk READER_ID ,fk
  • TITLE_ID , fk TITLE_ID ,fk
  • DATE

HISTORY table HISTORY

  • READER_ID
  • TITLE_ID
  • DATE_OF_BORROWING
  • DATE_OF_RETURNING

    1. Are these tables respect the 3NF Database Normalization? 这些表是否符合3NF数据库规范化?
    2. What if 2 authors work together for the same title? 如果2位作者为同一个头衔合作怎么办?
    3. The column Addresss should have it's own table? 列Addresss应该拥有自己的表吗?
    4. When a reader borrows a book, I make an entry in BORROWING table. 当读者借书时,我在BORROWING表中输入。 After he returns the book, I delete that entry and I make another one entry in HISTORY table. 他退回书后,我删除了那个条目,然后在HISTORY表中另外输入一个条目。 Is this a good idea? 这是一个好主意吗? Do I brake any rule? 我制止任何规则吗? Should I have instead one single BORROWING table with a DATE_OF_RETURNING column? 我应该用一个带有DATE_OF_RETURNING列的单个BORROWING表吗?

This looks a bit like a homework problem, but let me answer anyway: 这看起来有点像家庭作业问题,但让我回答:

  1. No, the tables are not in 3NF; 不,表格不在3NF; tables with surrogate keys rarely are. 具有代理键的表很少。 For example, the READERS table has two candidate primary keys: READER_ID and (First_Name, Last_Name). 例如,READERS表有两个候选主键:READER_ID和(First_Name,Last_Name)。 Of course, that depends on your problem domain: if you're willing to have two separate individuals with the same name, address and phone, then it's in 3NF. 当然,这取决于你的问题领域:如果你愿意拥有两个具有相同名称,地址和电话的独立个人,那么它就是3NF。 Also, in my experience, 3NF is usually more trouble than it's worth. 另外,根据我的经验,3NF通常比它的价值更麻烦。
  2. Again, that depends on your problem domain. 同样,这取决于您的问题域。 You could create a many-to-many relation between AUTHORS and TITLES through an intermediate table. 您可以通过中间表在AUTHORS和TITLES之间创建多对多关系。
  3. See 1. 见1。
  4. You could dispense with BORROWING and create a perfectly working application, as HISTORY contains all information you need. 您可以省去BORROWING并创建一个完美的应用程序,因为HISTORY包含您需要的所有信息。 The less information you have to track, the better. 您需要跟踪的信息越少越好。

I would change the Titles to a MANY-TO-MANY, and leave the addresses. 我会将标题更改为许多,并保留地址。

TITLES table TITLES

  • TITLE_ID , PK TITLE_ID ,PK
  • NAME

TitleAutors table TitleAutors

  • TITLE_ID , TITLE_ID
  • AUTHOR_ID

You could change the BORROWING table to have the status of the entry (OUT, IN, MISSING, UNKNOWN) and have a STATUS_DATE. 您可以将BORROWING表更改为具有条目的状态(OUT,IN,MISSING,UNKNOWN)并具有STATUS_DATE。

How do you expect anybody to seriously answer this question without any knowledge of your business domain ? 在没有任何业务领域知识的情况下,您如何期望任何人认真回答这个问题?

In order to answer this question earnestly, one needs to know the entire set of functional dependencies that govern your data, and you have not provided those. 为了认真回答这个问题,我们需要知道管理数据的整套功能依赖关系,而你却没有提供这些依赖关系。

For your scheme to be in 3NF, for example, it would require that domainID -> titleID, or, in other words, that there is only one title for each domain, and that knowing the domain implies that you can know the title. 例如,对于你的方案是3NF,它需要domainID - > titleID,换句话说,每个域只有一个标题,知道域意味着你可以知道标题。 On the face of it, that seems curious, but the only one who can tell for sure whether or not this is an accurate representation of the business reality that you're dealing with, is you. 从表面上看,这似乎很奇怪,但是唯一能够确定这是否是您正在处理的商业现实的准确表示的人,就是您。

An additional thought that occurred to me after reading others comments is. 在阅读其他评论后,我想到了另一个想法。

  • Can a author be a reader? 作者可以成为读者吗? (And vis-versa) (反之亦然)

If so you may have redundant first and last names entered into your system, and it would be susceptible to update anomalies. 如果是这样,您可能会在系统中输入多余的名字和姓氏,并且可能会更新异常。 For example if Jane Smith was a reader and an author and got married and her Surname changed to Williams then the possibility for updating her Reader last name and not her author last name would exist. 例如,如果简史密斯是读者和作者并结婚并且她的姓氏改为威廉姆斯,则存在更新她的读者姓氏而不是她的作者姓氏的可能性。

You would fix this by perhaps creating a User table where you have two Foreign keys for a Authors and Readers Table. 您可以通过创建一个User表来修复此问题,其中您有两个用于作者和读者表的外键。 Just a thought... ;) 只是一个想法... ;)

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

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