简体   繁体   English

如何避免数据库设计中的循环引用?

[英]How can I avoid the circular reference in my database design?

I have designed a database for a transport management program. 我已经为运输管理程序设计了一个数据库。 And one part seems to be OK, but I'm not sure how to store a combination from Package, Price and Version to a Project, to avoid a circular reference. 一部分似乎还可以,但是我不确定如何将Package,Price和Version的组合存储到项目中,以避免循环引用。

Just a short explanation of the database: A Package can have one to many Prices and has one to many Versions. 只是对数据库的简短解释:一个包可以具有一对多的价格,并具有一对多的版本。 So the Prices are independent from the Version. 因此,价格与版本无关。 Eg if you have 2 Versions, they have the same Price. 例如,如果您有2个版本,则它们具有相同的价格。 A Version can have one to many Equipment's and also a Equipment can belong to many Versions. 一个版本可以具有一对多的设备,并且一个设备可以属于多个版本。 A User filters over Package and chooses a Package, after that he chooses the Version and the Price and stores this in Project_Has_Packages. 用户筛选“软件包”并选择一个软件包,然后选择“版本”和“价格”,并将其存储在Project_Has_Packages中。 Just as you see in the picture. 就像您在图片中看到的一样。 Database Design Picture 数据库设计图片

My approach was, that the PackageName only comes from the Package-Table and the VersionName and PriceName from the specific Tables. 我的方法是,PackageName仅来自Package-Table,而VersionName和PriceName来自特定的表。 In the Pricing-Table and Version-Table I need the PackageName to make the entries unique, because it'll could be you have “Package1” and “Version1” and “Version2” and also “Package2” with “Version1” and “Version2”. 在Pricing-Table和Version-Table中,我需要PackageName来使条目唯一,因为它可能是您拥有“ Package1”,“ Version1”和“ Version2”以及“ Package2”和“ Version1”和“ Version2” ”。 The Versions are different because of the different Equipment, which belongs to the Version. 版本不同是因为属于版本的设备不同。 If I make the VersionName unique (“ver1 Pack1”) then the database isn't normalized any more. 如果我使VersionName唯一(“ ver1 Pack1”),则数据库将不再规范化。 Is there a possibility to avoid the circular reference and how can I change the design to avoid this? 有可能避免使用循环参考,如何更改设计以避免这种情况? Thinking the whole day about it and I can't see the wood for the trees anymore. 一整天都在思考,我再也看不见树木的树木了。

The main problem with your table design is that you use real data (strings) for keys. 表设计的主要问题是您将真实数据(字符串)用作键。 This is biting you in the butt now and will continue to do so. 这现在正在咬你,并且会继续这样做。

Try adding a auto-increment int ID as primary key for each table and corresponding foreign keys in the chiöd tables. 尝试为每个表和chiöd表中的相应外键添加一个自动递增的int ID作为主键。

I believe the "problem" with the circular keys are mote after that?! 相信带有圆形键的“问题”在那之后是微不足道的吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM