-2

I am working on an app and creating models now. I think this is a basic 1N normalization question but am not sure. Should I break location/address out as a separate table?

Let's say I have Parents and Children. Sometimes I will have children with no currently identified parents, and found at x location. Sometimes I will know that parents live at address y location, but then move to z. They may have known children, 1,2,3. Sometimes I will have children (1 and 2) at a shelter at location r, with known parents at location s. Sometimes I will have child 1 and not know s/he is related to child 3 at location r and s and their parents are f and need to be re-united. So parents are a one and children many. Children and parents are always at a specific location but this can change and I need to track that. I need to be able to say we found child 3 here and they moved to shelter x, then y then got reunited with parent.

Should location/address be a separate table or is it more helpful to have location/address in parent, children, and shelter tables?

asked Mar 26, 2020 at 19:37
4
  • 2
    If you are looking to represent your data in a relational database, then I'd recommend starting with relational database modelling and put your data into 3rd Normal Form - i.e. eliminate redundant data, non-key dependencies and transitive dependencies. Object-Orientation doesn't really play a part. In fact, it can potentially lead you down a bad path if you happen to fall into the trap of viewing your relational tables through the prism of Object-Orientation. Remember that your Database schema does not need to affect or constrain the structure of the rest of the app. Commented Mar 27, 2020 at 0:16
  • 2
    To add to the comment from @BenCottrell, a class in the software can easily map to either part of a table in the database or to a join of multiple tables. Commented Mar 27, 2020 at 7:23
  • I agree with Ben, don't start thinking in OOP for this problem yet. Get a good database structure first, then your code can be structured based on the UI needs later. Also, OOP does not mean you need just one class for 'Parent', you can have as many classes as needed that happen to interact with the 'parent' database structures/rows. Commented Mar 27, 2020 at 14:59
  • Follow a published academic textbook on information modelling, the relational model & DB design & querying. (Manuals for languages & tools to record & use designs are not such textbooks.) (Nor are wiki articles or web posts.) Ask 1 specific researched non-duplicate question where stuck. Right now you are just asking for us to rewrite a textbook with a bespoke tutorial & you have shown no research effort on answering it. Please see How to Ask, hits googling 'stackexchange homework' & the voting arrow mouseover texts. Commented Oct 13, 2020 at 9:05

1 Answer 1

0

I'd start with separate tables representing the following:

  • Person - common struct for both parents and children

  • ParentChildRelationship - has col for parent ID and a col for child ID, this way you can have as many 'generations' as needed, because children can have children. In your case a 16 year old child might also have a 1 year old child of their own and you can construct a family tree if needed. This also means a child without a known parent just has a row in the Person table and no rows here (yet).

  • ShelterLocation - address/details of physical location.

  • PersonAtLocation - holds person ID, shelter ID, datetime for when the person arrive, nullable datetime (defaults to null) for when the person left. Update the nullable datetime to 'now' when the person leaves that shelter location, regardless of whether they go to a new shelter location (which would be a new row in this table if they do so).

answered Mar 27, 2020 at 14:28
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.