[英]Database Schema relationship design
嗨,您好,
我是数据库设计的新手,我正在尝试为模型设计一个非常简单的模式。
只是想知道这是否是设计它的最佳方式,因为这是我的第一次,并且不想在没有外观的情况下构建它。
Pokemon table:
name, id (PK), type(FK), image and regionID(fk)
type
是Type
表中的Foreign Key,具有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
:
这是我第一次制作数据库架构,请让我知道它的外观!
谢谢
一般来说:
User
不是每个Users
现在你的情况:
Pokemon
和Type
之间存在多对多的关系。 所以我会从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)
也是Pokemon
和Region
之间的多对多关系。
通常,要表示多对多关系,您需要在两个表之间使用查找表。
类似A(id) - > Lookup(A.id,B.id)< - B(id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.