2016-05-14 177 views
1

enter image description here數據庫架構設計的關係

您好,

我是新來的數據庫設計,我想設計一個模型非常簡單的模式。

只是想知道這是否是設計它的最佳方式,因爲這是我第一次,並且不想在沒有外觀的情況下建立它。

Pokemon table:

  • 我得到name, id (PK), type(FK), image and regionID(fk)
  • typeType表的外鍵,並具有one-to-many關係。這聽起來是對的嗎?我在想這是因爲one pokemon can have multiple types?另外multiple pokemon can have multiple類型對我來說很有意義。
  • regionID是來自Region表的外鍵。 many pokemon can live in many regions對我有意義。或者應該是one pokemon can live in multiple regions?或multiple regions can have multiple pokemon

Region table:

  • 我只有在這裏得到了PK。我是否也需要LocationWithinRegion表中的FK?
  • 這裏我有一個one to many的關係,因爲1 region can have multiple locations但是one location can't have multiple regions。這是正確的嗎?

Type table

  • 我提出的所有這些類型的比特,所以我可以表示一個布爾值。我希望能夠查詢寵物小精靈表並查找所有相關數據,並在可找到該寵物小精靈的地區找到真或假。

這是我第一次製作數據庫模式,請讓我知道它是怎麼樣的!

感謝

+0

pokmontype主鍵類型需要匹配與FK pokmon表 –

+0

看起來像它已經。 「類型表」的「PK」是口袋妖怪表中的「FK」。 –

回答

0

一般:

  • 提供每個表有奇異的名字。 User而不是Users因爲每個
    行代表一個用戶。
  • 爲每個表提供可能的最小主鍵。在大多數 的情況下,一個身份int會做。
  • 在外鍵列上創建索引。這將有助於加入。

現在你的情況:

PokemonType之間的許多一對多的關係。所以我會從Pokemon表中刪除PokemonType string,我會創建一個表Type(Id int Identity PK, Description string Unique)和一張桌子PokemonType(PokemonId int FK on Pokemon, TypeId int FK on Type, PK on both columns)

也就是PokemonRegion之間的許多一對多的關係。

通常,爲了表示多對多關係,您需要兩個表之間的查找表。

有點像(ID) - >查找(A.id,B.id)< - B(ID)