[英]Database Schema relationship design
Hi there, 嗨,您好,
I'm new to database design and I'm trying to design a very simple schema for the model. 我是数据库设计的新手,我正在尝试为模型设计一个非常简单的模式。
Just wondering if this will be the best way to design it, since this is my first time and don't want to build this out without a lookover. 只是想知道这是否是设计它的最佳方式,因为这是我的第一次,并且不想在没有外观的情况下构建它。
Pokemon table:
name, id (PK), type(FK), image and regionID(fk)
我得到name, id (PK), type(FK), image and regionID(fk)
type
is a Foreign Key from the Type
table and has a one-to-many
relationship. type
是Type
表中的Foreign Key,具有one-to-many
关系。 Does that sound right? 听起来不错吗? I'm thinking this because one pokemon can have multiple types
? 我在想这个因为one pokemon can have multiple types
? Also multiple pokemon can have multiple
types makes sense to me. 还有multiple pokemon can have multiple
类型对我有意义。 regionID
is a foreign key from Region
table. regionID
是Region
表中的外键。 many pokemon can live in many regions
makes sense to me. many pokemon can live in many regions
对我有意义。 Or should it be one pokemon can live in multiple regions
? 或者它应该是one pokemon can live in multiple regions
? Or multiple regions can have multiple pokemon
? 或者multiple regions can have multiple pokemon
? Region table:
PK
in here. 我这里只有PK
。 Do I need the FK from LocationWithinRegion
table as well? 我还需要LocationWithinRegion
表中的FK吗? one to many
relationship here, Because 1 region can have multiple locations
but one location can't have multiple regions
. 我在这里有one to many
关系,因为1 region can have multiple locations
但是one location can't have multiple regions
。 Is this right? 这是正确的吗? Type table
: Type table
:
This is my first time making a database schema so please, let me know how it looks! 这是我第一次制作数据库架构,请让我知道它的外观!
Thanks 谢谢
In general: 一般来说:
User
not Users
as each User
不是每个Users
Now in your case: 现在你的情况:
There is a many-to-many relationship between Pokemon
and Type
. Pokemon
和Type
之间存在多对多的关系。 So I would drop the PokemonType string
from the Pokemon
table and I would create a table Type(Id int Identity PK, Description string Unique)
and a table PokemonType(PokemonId int FK on Pokemon, TypeId int FK on Type, PK on both columns)
所以我会从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)
Also is a many-to-many relationship between Pokemon
and Region
. 也是Pokemon
和Region
之间的多对多关系。
In general, to represent a many-to-many relationship, you need a lookup table between the two tables. 通常,要表示多对多关系,您需要在两个表之间使用查找表。
Something like A(id) -> Lookup(A.id, B.id) <- B(id) 类似A(id) - > Lookup(A.id,B.id)< - B(id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.