假设我有一个包含这些表的数据库
Car --> Has Dealerships --> Has Demographic --> Has Revenue
在推出后,客户说他们希望汽车有型号,每个型号都应该有经销商
所以我的结构变成了
Car --> Has Model --> Has Dealerships --> has Demographic --> Has Revenue
我如何迁移到第二个数据库结构?我需要在Car
和Dealership
之间切断外键才能使用。我是否只是拍摄旧数据库的快照,并在知道如何处理它的上下文中编写一个包装器?
答案 0 :(得分:1)
我的理解是它应该是Model --> Has Cars
,而不是Car --> Has Model
。在我看来,-->
指定更加一致。
因此,正确的最终关系链可能看起来像这样:
Model --> Has Cars --> Has Dealerships --> Has Demographic --> Has Revenue
我会想象以下一系列动作:
创建并填充Models
表。此时您的架构:
Model Car --> Has Dealerships --> Has Demographic --> Has Revenue
向ModelID
添加Cars
列,并根据您的业务需求使用正确的Models
引用填充该列。它会给你以下结果:
Model --> Has Cars --> Has Dealerships --> Has Demographic --> Has Revenue
向ModelID
添加Dealerships
引用,通过使用当前关系将Dealerships
加入Cars
来填充该引用。您最终会在Dealerships
和Models
,直接和Cars
之间建立双重关系,如下所示:
Model --> Has Dealerships --> Has Demographic --> Has Revenue \ / \-> Has Cars -/
删除Cars --> Dealership
外键,删除Dealerships.CarID
引用列。这将是您的最终结果:
Model --> Has Dealerships --> Has Demographic --> Has Revenue \ \--> Has Cars