首先,我已閱讀this,this和this有關此事的主題。我認爲我明白這一點,但我仍然不確定我是否以正確的方式進行,因爲我幾乎只能確定關係。我基本上想知道我是否正朝着正確的方向前進。數據庫,仍然不確定關於定義關係
我正在創建一個數據庫,其中用戶可以創建一個配置文件(帶有免費和付費版本)和發佈新聞項目。其他用戶可以回覆這些項目,反應可以獲得評分。這是網站功能的一小部分,但這是我擔心的部分。我寫下了以下(每一行代表兩個表之間的鏈接):
USERS: One user can define additional info once [Identifying, 1:1] One user can have one sexual preference [Identifying, 1:1] One user can have one payment status [Identifying, 1:1] One user can define five questions [Identifying, 1:n] One user can define three additional information rows [Identifying, 1:n] One user can define three interests [Identifying, 1:n] NEWS: One user can post multiple news items [Identifying, 1:n] One news item can receive multiple comments [Identifying, 1:n] Each comment has one author (user) [Identifying, 1:1] Each comment can receive one rating [Identifying, 1:1] Each rating can be placed by one user at a time [Identifying, 1:1] PAYMENT: One promotion can either apply for all users or for one specific user [Non-identifying, 1:n]
幾乎所有的上述關係的確定,這讓我質疑閹羊我瞭解此事。
除此之外,我使用表格(status
),其中包含(除其他之外)用戶的付款狀態和另一個表格(promotions
),該表格包含可能的促銷活動。我不清楚,我想我將promotions
表連接到status
或user
表。
有人可以幫我解決疑惑嗎?
儘管每個評論都有一個作者,但是每個作者都可以做出很多評論 - 所以對作者關係的評論肯定是n:1。另外,每個評論當然可以收到很多評分(每個用戶評分),因此對評分關係的評論是1:n,並且一個用戶可以做出很多評分,因此對用戶關係的評分爲n:1。 – 2013-03-26 13:04:28
有道理,thnx!所以據我瞭解另一部分,一個非識別關係是非常罕見的。?? – Maurice 2013-03-27 07:52:05
不一定 - 請注意,我以前的評論完全是關於某些關係的*基數*,而不是他們是否識別/不識別關係。正如Bill Karwin在這個問題的最高評價/接受的答案中寫的:http:// stackoverflow。com/questions/2814469(你在你的問題中被鏈接了),「一個識別關係的技術定義是孩子的外鍵是其主鍵的一部分」。因此,它將取決於您在設計中將哪些字段用作鍵。 – 2013-03-27 11:08:34