2011-09-29 40 views
0

用戶只能擁有一個博客(用戶擁有博客)
博客可以有多個帖子。
組只能有一個博客(但沒有特別的用戶擁有該博客,假定組所有者創建的博客從而用戶ID是唯一的一個不那麼需要組博客子類型的用戶的博客屬性)
這是5NF的設計嗎?

enter image description here

刪除group_blog_post時,底層的blog_posts行也應該被刪除,這是否最好使用觸發器完成?

+0

什麼問題:數據庫是在5NF還是應該使用觸發器來刪除blog_posts? – Wil

+0

屬於多人的羣組博客和博客有什麼區別?你的設計看起來過於複雜... – Blindy

+0

我想檢查這是否是有效的5NF設計。組博客屬於一個組(沒有特定的用戶擁有/創建它)。用戶博客由用戶創建。因此,userid是user_blogs的一個屬性,但不是group_blogs。因此博客成爲超類型和group_blogs,user_blogs成爲子類型。 – firebird

回答

1

對於5NF中的表格,它必須首先在4NF中。要在4NF,它必須首先在3NF。等等,降到1NF。簡單地說,較低的標準形式必須與候選鍵和非素數屬性之間的依賴性有關。但是我們可以看到的唯一的非素數屬性是「title」和「is_private」。所以真的沒辦法告訴。

以一張表爲例,如果沒有其他列,「group_users」在5NF中。

後來

如果您在擴展表group_users這樣

create table group_users (
    group_id integer not null references groups (group_id), 
    user_id integer not null refrences users (user_id), 
    user_type_id integer not null references user_types (user_type_id), 
    primary key (group_id, user_id) 
); 

那麼你還在5NF。 「user_type_id」列不僅僅依賴於user_id - 如果是的話,你不會在2NF。但是user_type_id不是用戶的一個屬性,這是該特定組中的用戶的屬性。沒有部分密鑰依賴性;沒有傳遞依賴;沒有獨立的多值事實;沒有連接依賴關係;所以它在5NF。

該結構允許每個用戶每組只有一個user_type_id。如果您認爲用戶應該有多個用戶類型各組中,那麼這個

create table group_users (
    group_id integer not null references groups (group_id), 
    user_id integer not null refrences users (user_id), 
    user_type_id integer not null references user_types (user_type_id), 
    primary key (group_id, user_id, user_type_id) 
); 

也5NF。沒有部分密鑰依賴性;沒有傳遞依賴;沒有獨立的多值事實;沒有連接依賴關係;所以它在5NF。

+0

說組用戶有另一個欄目說明用戶類型(管理員,用戶,主持人等)。所以它不會在5nf,因爲該用戶類型不會是密鑰(groupid,userid)的一部分?那麼用戶類型屬性去哪裏? – firebird

+0

@firebird:更新了答案。 –