Does data redundancy in different tables not follow Third Normal Form (3NF)?

眉间皱痕 提交于 2019-12-08 06:29:51

问题


I have 4 tables. Each of them contain the following attributes:

Table 1 :
 Person (Id (Primary key), Name, Occupation, Location, SecondJob, PerHour, HoursWorked, Phone, Workphone)

Table 2 :
 Job (Id (Foreign key that refers to Person), Title, Name, Location, Salary)

Table 3 :
 SecondJob (Id (Foreign key that refers to Person), Title, Name)

Table 4:
 PhoneNumber (Id (Foreign key that refers to Person), Name, Phone, Workphone)

I can obtain the values of each attribute like Name, Title, Phone and Workphone from the Person table with the following psuedo SQL statement:

Select (ATTRIBUTE NAME) FROM Person WHERE Id IN (PERSONS ID)
  1. Does the fact that some of the information is being repeated in DIFFERENT TABLES (Data Redundancy), break (ie, not follow) the Third Normal Form (3NF)?

    Or should the values be put into the other Tables separately and reason what attribute is identifying with the Primary Key of the Table?

  2. I calculate Salary in Job by getting PerHour and HoursWorked from Person, then multiply them. I have also heard that this is redundant Data, due to the fact that is is data that you could extrapolate from existing Data within the Tables.

    But, does this break the Third Normal Form??


回答1:


Does the fact that information is repeated in DIFFERENT TABLES (Data Redundancy), break against 3NF Normalization?

No. A table value or variable is or isn't in a given NF. This is independent of any other table. (We do also talk about a database being in NF when all of its tables are in that NF.)

Normalization can be reasonably said to remove redundancy. But there is lots of redundancy not addressed by normalization. And there is lots of redundancy that is not bad. And duplication is not necessarily redundancy. Just because data is repeated doesn't mean "information" is repeated. What data says by being or not being in a table depends on the meaning of the table.

But you seem to think that just because duplicating data in a different table doesn't violate 3NF that it doesn't violate other principles of good design. That's wrong. Also, it's 5NF that matters. The only reason lower NFs are used is that SQL DBMSs don't support 5NF well.

Or should i just put in the values into the other Tables seperately and reason what attribute is identifying with the Primary Key of the Table?

I guess you are trying to say, Should I only put the values in one table each and reconstruct the second table via queries involving shared keys? Ie, if you can get the values in a column by querying the rest of the database then should you avoid having that column? Generally speaking, yes.

Your question assumes a misconception. It's not a matter of "(exclusive) or" here. You should do both.

I calculate Salary in Job by getting PerHour and HoursWorked from Person, then multiply them. I heard that this is also redundant Data, due to it being data that you could extrapulate from existing Data in the Tables.

It is redundant given the rest of the database, because you could use a query instead. And if you don't constrain salary values appropriately then that is bad redundancy. Even if you do the column and constraint complicate the schema.

But does it break 3NF Normalization?

No, because the NF of a table is independent of other tables. But that doesn't mean it's ok.

(If you added Salary to Person, the new table would not be in 3NF. But then, SQL DBMSs have computed columns that make that ok, by making the non-3NF table with Salary a view of the 3NF table without it.)

Learn some database design method(s) and how they apply principles of good design. Your tables needlessly address overlapping aspects of the application. Also learn about JOIN in writing queries.



来源:https://stackoverflow.com/questions/40696601/does-data-redundancy-in-different-tables-not-follow-third-normal-form-3nf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!