Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8468467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:56:30+00:00 2026-06-10T15:56:30+00:00

I have a weird database design issue that I’m not sure if I’m doing

  • 0

I have a weird database design issue that I’m not sure if I’m doing this right or not. Since my current design is really complicated, I’ve simplified it in the following diagram with a comparison using houses and occupants (not my actual entities).

So, here is what part of the database design looks like:

Standard Conditions:

  • Multiple houses
  • Multiple floors per house
  • Multiple bedrooms per floor

Not-so-standard Conditions:

  • Each occupant can live in multiple houses
  • Each occupant can have multiple bedrooms per house
  • Each occupant can only have one bedroom per floor, per house (this is the tricky part) For example, they can have one bedroom on floor 1, one bedroom on floor 2 and one bedroom on floor 3, but never two bedrooms on the same floor

Thus, what I’m trying to accomplish is this. In the app design, I know the house, I know the floor and I know the occupant. What I need to find out with this information without the user specifying is what bedroom the occupant has based on those 3 criteria. There are two solutions. The first is that in the occupants_has_bedrooms table, I make the primary key the occupants_id, bedrooms_floors_id and the bedrooms_floors_houses_id. However, when I take away bedrooms_id from the primary key, the table is no longer an identifying relationship to the parent (bedrooms). It is an identifying relationship though because it couldn’t exist without the parent. Therefore, something tells me I need to keep all four ids as the primary key. My second option is a unique index between those three values, however this is when I considered I may be approaching this wrong.

How do I accomplishing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:56:32+00:00Added an answer on June 10, 2026 at 3:56 pm

    Here’s a general database design strategy that is not specific to MySQL but should still be helpful.

    It’s good that you know how you are going to query your data, but don’t let that overly affect your model (at least at first).

    The first thing to be clear on is what is the PK for each table? It looks you are using composite keys for floors and bedrooms. If you used an informationless key (ID column per table) strategy for all tables except your intersection table Occupants_has_bedrooms, it would makes your joins simpler. I’m going to assume you can, so here’s how to go from there:

    The first thing I would change is to get rid of floors_house_id column in bedrooms – this is now redundant and can be gotten from a join.

    Next, make the following changes to occupants_has_bedrooms:

    1. The PK for should only be two columns, occupants_id and bedroom_id. (why? Because a primary key should only contain enough info to uniquely identify a row).
    2. Remove the bedrooms_floors_houses_id, as that’s determined by bedrooms_floors_id and is not needed.
    3. add a unique constraint on (occupants_id, bedrooms_floors_id) to enforce your “not so standard” conditions.

    Finally, do an inner join with all tables except Occupants, add your three conditions in the WHERE clause. This should get you the result you want. If you really want the composite keys, you can still do it cut it gets messy. Sorry I’m not near an editor or I’d diagram it for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this very weird issue that I cant really get why it's not
I have this weird issue. I am trying to create a service that synchs
I have this weird problem. I have defined a column in a SQLite database
I have this weird behavior in C which I do not understand. It is
I have a weird issue which I'm sure is because I don't understand all
I have a really weird problem with a small database. the table has about
Weird question, but I'm not sure if it's anti-pattern or not. Say I have
I have a weird issue where I have a stored procedure that is inserting
Really weird problem. I have a tableView that pulls data out of a Core
This is pretty weird. I have my Profiler open and it obviously shows that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.