2012-04-30 178 views
-2

我想管理一個n標籤評論系統並設計一個這樣的數據庫結構。 my database structure評論系統的結構

我想設計一個支持未註冊用戶的評論審覈的數據庫。我需要的功能是當發佈評論時

  • 如果用戶註冊,它會直接出現。除此以外;
  • 該帖子必須由主持人檢查纔出現。

請建議對我的數據庫模式進行可能的更改以支持此功能。

+0

在我爲您寫回答之前,幾乎沒有問題:1)您如何識別用戶是否已註冊,您是否擁有RegisteredUser表? 2)你已經顯示了'BlogSetting'表,但它沒有出現任何鏈接。是否有一個'Blog'表是'BlogSetting'和'BlogPost'的父親? (提示:應該有!)3)'BlogBlockedUser'如何進入? – Jamiec

+0

@Jamiec雅我有'RegisteredUser' table.Blog seeting是頁面加載時獲取。它由我的'sp'管理。 –

回答

1

看起來你有或多或少的需求,爲了做你想做的事情。當用戶創建一個新的評論的過程如下

if the user is registered, and not blocked 
    create BlogComment record with: 
      IsApproved=true 
      IsBlocked=false 
      UserId=registered userId 
      UserName = null 
if the user is registered and blocked 
    create BlogComment record with 
      IsApproved=false 
      IsBlocked=true 
      UserId=registered userId 
      UserName = null 
if the user is unregistered 
    create BlogComment record with 
     IsApproved=false 
     IsBlocked=false 
     UserId=null 
     UserName=user's name 

當你拉出來的意見,看看下面你要像

SELECT Comment, ISNULL(bc.UserName, ru.UserName) AS UserName 
FROM BlogComment bc 
LEFT JOIN RegisteredUser ru 
    ON bc.UserId = ru.Id 
WHERE postId=<current PostId> 
AND IsApproved=1 

這將退出所有已批准評論的查詢(那些帖子來自注冊用戶或已註冊的未註冊用戶)以及他們的用戶名(對於註冊用戶,這將是他們的用戶名RegisteredUser表,未註冊它將保存在BlogComment表中的註釋旁邊)

最後,當你想拔出職位名單的主持人,中度

SELECT * 
FROM BlogComment 
WHERE IsApproved=0 
AND IsBlocked=0 

然後,您可以更新他們接受IsApproved=1記錄。

+0

非常感謝給我一個很好的方法。我明白了我想要的。 –