开发者

do these tables fit the database First Normal Form?

table users

userId    name     company    company_address     url

1         Joe       AB开发者_JAVA技巧C       Work Lane         abc.com

2         Jake      ABC        Work Lane        xyz.com

3         tom       XYZ       Job Street        abcde.com

4         jim      XYZ       Job Street         fexyz.com

the second table

id          name          favourite_food_1          favourite_food_2   

1           Sam              Curry                  Steak       

 2           Lucy           Chicken                      Burgers                 

if the table don't fit for the 1NF,why? thank you.


The first table fits 1NF. The second does not - there's a repeating group with the two favorite food fields. Not everyone necessarily has two favorite foods (or any favorite foods at all, or has 3+ favorite foods), so those fields are nullable, and therefore causes the table to fail 1NF.


Doesn't 1NF only mean each value has to be atomic? In other words, every relational database table is in 1NF, since sets of values aren't allowed.


1NF sets the very basic rules for an organized database:

1: Eliminate duplicative columns from the same table. 2: Create separate tables for each group of related data and identify each row with a unique column (the primary key).

The problem with your Database tables is "Name"(duplicate column).


Every relational table always satisfies 1NF. A SQL table is in 1NF if it accurately represents a relation, i.e. it has unique column names and doesn't permit nulls or duplicate rows.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜