0

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.

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. E.g. if you have 2 Versions, they have the same Price. 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. 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. 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”. 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. 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.

StefanS
  • 33
  • 5

1 Answers1

1

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.

I believe the "problem" with the circular keys are mote after that?!

Mattias Åslund
  • 3,877
  • 2
  • 18
  • 17
  • You are right! I didn't see that. VersionName and PricingName isn't a unique expression contrary to PackageName. I just added as key VersionID and PriceID, and the circular reference is also solved and the PackageName I use as non identifying foreign key. The PackageName stays as a String, because I want the expression to be unique. Thanks for your help! – StefanS Jun 29 '16 at 11:58