Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA:…

715 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