Go Premium for a chance to win a PS4. Enter to Win


database design

Posted on 2016-08-31
Medium Priority
Last Modified: 2016-09-01
Hi Experts,

Here's a fairly simple database design question, but I'd like some input from all y'all experts.

I've got this system where Products need to be tested, and tests are always tied to production Lots, but at times, Tests need to be set up before the Lot_Number is known. In such a case, is it better to put the Product_ID in both the Test and the Lot tables, or only keep it in the Lot table, and leave the Lot_Number null until it is known? (I'm guessing that's the better option, but not sure.)


Test_ID int
Lot_ID int

Question by:tablaFreak
  • 3
  • 2
  • 2
  • +3
LVL 35

Expert Comment

by:Terry Woods
ID: 41779509
In just one place is generally better, as data can't get out of sync (eg a Test where the Product_ID is different to the Product_ID for the associated Lot_ID).
LVL 52

Expert Comment

by:Vitor Montalvão
ID: 41779535
If Lot_ID is not part of the Primary Key then let it to be nullable as you can update it later when you know the Lot number.
LVL 51

Expert Comment

by:Steve Bink
ID: 41779540
What data points do you need for a test, which are not also related to the results of the test?  

If the test is something you need to set up separately from the actual act of testing, perhaps you need to break your table into "tests" and "test_instances".  This is much more efficient if test configurations are meant to be reused on successive lots of the same product, but that is not a requirement.
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

LVL 39

Expert Comment

by:Aaron Tomosky
ID: 41779986
In this example leave the lot number where it is and have lot Id nullable.

It sounds like you might actually have three tables: testtemplates, lots, and tests that are a template on a lot.
LVL 51

Assisted Solution

by:Mark Wills
Mark Wills earned 500 total points
ID: 41780144
I am inclined to agree with some of the assertions / observations made by Steve and Aaron above.

In so much as you may need further tables.

You say each product must be tested, but I don't really see that specific relationship in your design until you incorporate Lots.

You say that tests need to be set up before production Lots are known.

Implied, but not stated, we can only assume that a Test is likely (or sounds) to be product specific and could be established before the production lot is known.

It sounds like your Production Lots are akin to a "batch" or "job".

So, would like to see something that formalises those immediately identifiable relationships
1) Test
2) Test + Product
3) Product
4) Product + Production Lot

For me, the confusion seems to be in your first table which tries to establish Test + Lot but Lot is not known yet.

That doesn't mean that you can't leave Lot_Number nullable, but it is unknown as to the relationship between Lot_Number and Lot_Id (or the timing of when that relationship is known).

Then as tests are performed, they create the test results and Lot_Number would then be known (so insert the result rather than update the lot_number)

Like the other experts, there seems to be some missing information as to the relationships to give an accurate appraisal of your design....

However, to answer your question "In such a case, is it better to put the Product_ID in both the Test and the Lot tables" I would say a definitive YES given the information provided (and that is before we have to worry about the nullability of lot_number).


Author Comment

ID: 41780375
Hi Guys,

Thanks for the inputs. Yes, to clarify, not all Products are tested, only some, and in some cases, Tests are set up before Lots are known (as I mentioned), but there are so many variables in the Product formulation that it's rare that a single test configuration/instance is run more than once.

In fact there already is something of a Test Template table, which is called Specification, which is used to generate Test Line Items from a given product specs.  (Maybe irrelevant for what I'm asking). I simplified the model, trying to isolate my issue for this question, but there is a Test_Line_Item table which holds the actual Test Lines, and the Test table contains only the Test metadata. The issue is that I'm averse to storing Product_ID in the Test table as well as the Lot table since it definitely has to be in the Lot table, and I want to avoid the problem Terry pointed out of potential mis-matched Test.Product_ID and Lot.Product_ID. What I'm imagining is that the Lot table would have the Product_ID populated with the Product being tested, so the Test.Lot_ID would refer to the Lot record with a null Lot_Number. The risk there is the user could potentially create a new Lot record for the Lot with a test already tied to it, and inadvertently create orphaned Lot records, or Lots that would need to be merged or resolved. Maybe the best solution is to go ahead and keep Product_ID in both tables, and just make sure there aren't mismatches in the code? This would minimize user error, and leave the validation to the code. Perhaps safer in the long run, but it goes against good database design. Thoughts? Thanks a lot.

- Steve
LVL 35

Accepted Solution

Terry Woods earned 1000 total points
ID: 41780749
My feeling is at this point you're beginning to overthink it, and it doesn't matter too much either way. If you're worried about invalid data (and where reliable data is important, this is a big concern), instead put the time into setting up a script that runs regularly and sends an alert if invalid data detected. There might be other queries you could add to that too.
LVL 39

Assisted Solution

by:Aaron Tomosky
Aaron Tomosky earned 500 total points
ID: 41780759
Agreed. The quick and dirty method I've used is to write a " things that should not be" query that looks for inconsistencies. Null tests past a week old, product Ids not existing in two tables, etc...

Author Comment

ID: 41780771
Thanks guys, sounds good.

Author Closing Comment

ID: 41780772
thank you

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question