1
我拿到了Person
表,每个Person
都可以访问几个国家。每个Person
访问的国家存储在表CountryVisit
这是一个很好的数据库设计实践吗?
人:
PersonId,
Name
地区访问:
CountryVisitId (primary key)
PersonId (foreign key to 'Person.PersonId')
CountryName
VisitDate
对于CountryVisit
表,我的主键是CountryVisitId
这是一个identity
栏。这种设计将导致Person
只能有1 CountryVisit
,但CountryVisitId
可以是40。创建另一个代理键列作为标识列是否是一种更好的做法,而CountryVisitId
是每个PersonId
都唯一的自然键?
为什么不把'person','country'作为独立的表和映射表'CountryVisit'?这样你可以确保国家在拼写方面没有变化。 – davek 2014-11-22 16:04:25
是的,那是在我原来的设计中,我只是在这里做了一个更简单的设计来澄清我的问题 – user3340627 2014-11-22 16:05:44
如果用户多次访问同一个国家,您想存储什么? IE:这是1-n还是n-n关系? – 2014-11-22 16:06:46