數據庫規範化 2nf、3nf
我正在做關於數據庫規範化的作業。我必須將表格分解為顯示步驟的 3nf 表格
這是初始表:
|--------------------------------------------------------------------------------------------------------| |Pick_up | E# | E_name |Pick_up_cost | Rate_per_project| Hours worked|project_code|Project location | |--------------------------------------------------------------------------------------------------------| | | | | | 363 | 10 | 1 |Luton | | | | | 200 | 248 | 20 | 12 |Edinburgh | |London | 76 | Ali | | 322 | 18 | 11 |Glasgow | |--------------------------------------------------------------------------------------------------------| | | | | 300 | 363 | 1 | 1 |Luton | | | | | | 568 | 2 | 14 |Newcastle | | | | | | 568 | 1 | 14 |Newcastle | |Oxford | 142| Ronald | 300 | 248 | 5 | 12 |Edinburgh | |--------------------------------------------------------------------------------------------------------| | | | | | 363 | 11 | 1 |Luton | |Oslo | 76 | Shawn | 500 | 322 | 15 | 11 |Glasgow | ----------------------------------------------------------------------------------------------------------
填充後是:
|--------------------------------------------------------------------------------------------------------| |Pick_up | E# | E_name |Pick_up_cost | Rate_per_project| Hours worked|project_code|Project location | |--------------------------------------------------------------------------------------------------------| |London | 76 | Ali | 200 | 363 | 10 | 1 |Luton | |London | 76 | Ali | 200 | 248 | 20 | 12 |Edinburgh | |London | 76 | Ali | 200 | 322 | 18 | 11 |Glasgow | |Oxford | 142| Ronald | 300 | 363 | 1 | 1 |Luton | |Oxford | 142| Ronald | 300 | 568 | 2 | 14 |Newcastle | |Oxford | 142| Ronald | 300 | 568 | 1 | 14 |Newcastle | |Oxford | 142| Ronald | 300 | 248 | 5 | 12 |Edinburgh | |Oslo | 76 | Shawn | 500 | 363 | 11 | 1 |Luton | |Oslo | 76 | Shawn | 500 | 322 | 15 | 11 |Glasgow | ----------------------------------------------------------------------------------------------------------
1NF
Pick_up、emp_no、emp_name、pick_up_cost、rate_per_project、hours_worked、project_code、project_location
部分依賴:
Employee_no->emp_name,pick_up,pick_up_cost
Project_code->project_location, rate_per_project, hours_worked
2NF
Emp_no、emp_name、pick_up、pick_up_cost Project_code、project_location、rate_per_project、hours_worked
傳遞依賴: Pick_up->pick_upcost
我的問題是 2nf 形式的傳遞依賴是否正確?什麼是 3nf 形式?
一個簡單的助記符:
- 鍵(1NF - 沒有數據項在行中的多個位置重複)
- 整個密鑰(2NF - 與復合密鑰的一部分無關)
- 只有鍵(3NF - 與非鍵屬性無關)
. . . 所以幫助我科德。
我是一名學生,據我所知,
如果滿足以下條件,則一張表參與 1NF:
1.The table have a primary key 2.Do not have repetition groups(itens that repeat in the same row) 3.Each of it's fields is atomic (no need to decompose the value)
對於每個重複組,將其移動到一個新表並在其上包含原始表的鍵。
如果滿足以下條件,則該表適用於 2NF:
1.It is on the 1NF 2.All the table fields depends of the entirely primary key
下表CustomerCard( CustomerId , CardId , CardBrand) CardBrand 欄位只依賴於CardId 欄位,這樣應該移動到另一個表。卡(卡號,卡名)
參加 3NF:
1.It is on the 2NF 2.None of its columns have transitive dependencies 3.None of its columns have calculated fields
下表 Order( OrderId , CustomerId , CustomerName, CustomerCityId, CustomerCityName) Orbserve 下列傳遞依賴:
- 訂單 ID -> 客戶 ID -> 客戶名稱
- OrderId -> CustomerId -> CustomerCityId
- OrderId -> CustomerId -> CustomerCityId -> CustomerCityName
應該首先解決最簡單的依賴關係。CustomerId 程式碼將保留在 Order 表中,但依賴於 CustomerId 的列被移動到一個新表,其中 CustomerId 是主鍵,結果:
訂單(訂單編號,客戶編號)
客戶(客戶 ID、客戶名稱、客戶城市 ID、客戶城市名稱)
Order表的傳遞依賴被去掉了,但是我們還是需要分析一下表Customer。CustomerCityName 列僅取決於 CustomerCityId。然後我們需要再次創建一個新表 City( CityId , CityName),並且 CustomerCityId 仍然存在於 Customer 表中。
使用所有 3NF 的最終結果:
- 訂單(訂單編號,客戶編號)
- 客戶(客戶 ID,客戶名稱,客戶城市 ID)
- 城市( CityId , CityName)