2015-10-05 54 views
3

我有這個表,我必須正常化達到3NF正常化表

假設如下:

  • 一個訂單可以包含多種產品

  • 每當一個客戶下訂單,他們得到一個新的訂單號

  • 一個訂單屬於一個且只有一個客戶

    訂單(ORDERNUM,訂購日期,(產品編號,ProductDesc),CUSTID,客戶名稱,CustomerAddress)

到目前爲止,我已經做到了這一點

1FN

Orders (OrderNum, OrderDate, (ProductId,ProductDesc),(CustId,CustomerName,CustomerAddress, OrderNum)) 

2FN

Orders(OrderNum, OrderDate) 
Orders_Product(OrderNum, ProductId) 
Product(ProductId, ProductDesc) 
Customer_Orders(OrderNum, CustId) 
Customer(CustId,CustomerName,CustomerAddress) 

3 NF

的表已經完成3NF

Orders(OrderNum, OrderDate) 
Orders_Product(OrderNum, ProductId) 
Product(ProductId, ProductDesc) 
Customer_Orders(OrderNum, CustId) 
Customer(CustId,CustomerName,CustomerAddress) 

依賴

OrderNum  OrderDate,ProductId,ProductDesc,CustId, CustomerName, CustomerAddress 
    ProductId  ProductDesc 
    CustId  CustomerName, CustomerAddress 

是我2NF和3NF是否正確?在定義

+1

我認爲只有你的2NF是錯誤的。閱讀此:[第二範式](https://en.wikipedia.org/wiki/Second_normal_form) –

+2

我不記得2NF應該是什麼樣子。但是,在你的3NF模型中,我不認爲你需要Customer_Orders表。您應該在訂單表上擁有一個CustId。 –

+0

你爲什麼認爲他的2NF是錯的? – AnhTriet

回答

3

基礎由Wiki:一臺是2NF如果是1NF且沒有非主屬性是依賴於表任何候選鍵中的任何真子集。大多數表格只有2列,所以他們滿意這一點。對於Customer(CustId,CustomerName,CustomerAddress),候選密鑰爲CustId,其他2列完全依賴於整個候選密鑰,則可以。

對於3NF,Wiki表示:表中的所有屬性僅由該表的候選鍵確定,而不由任何非素數屬性確定。如你所見,你的桌子都滿意了。

然而,正如你說:

的訂單隻屬於一個且只有一個客戶

所以,我不認爲你需要Customer_Orders號。您應該將其刪除,並將CustId放入Orders表中。所以,你的Orders表將如下所示:Orders(OrderNum, OrderDate, CustId)