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

  • Home
  • SEARCH
  • 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 63405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:37:39+00:00 2026-05-10T18:37:39+00:00

How would you model booked hotel room to guests relationship (in PostgreSQL, if it

  • 0

How would you model booked hotel room to guests relationship (in PostgreSQL, if it matters)? A room can have several guests, but at least one.

Sure, one can relate guests to bookings with a foreign key booking_id. But how do you enforce on the DBMS level that a room must have at least one guest?

May be it’s just impossible?

  • 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. 2026-05-10T18:37:40+00:00Added an answer on May 10, 2026 at 6:37 pm

    Actually, if you read the question, it states booked hotel rooms. This is quite easy to do as follows:

    Rooms:     room_id primary key not null     blah     blah  Guests:     guest_id primary key not null     yada     yada  BookedRooms:     room_id primary key foreign key (Rooms:room_id)     primary_guest_id foreign key (Guests:guest_id)  OtherGuestsInRooms:     room_id foreign key (BookedRooms:room_id)     guest_id foreign key (Guests:guest_id) 

    That way, you can enforce a booked room having at least one guest while the OtherGuests is a 0-or-more relationship. You can’t create a booked room without a guest and you can’t add other guests without the booked room.

    It’s the same sort of logic you follow if you want an n-to-n relationship, which should be normalized to a separate table containing a 1-to-n and an n-to-1 with the two tables.

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

Sidebar

Related Questions

I have an ActiveRecord model that I would like to convert to xml, but
If I have two objects that have a many-to-many relationship, I would typically model
I would like to use Markov models for some architecture simulations, but don't have
How would you model a turn-based game server as a RESTful API? For example,
How would you model a simple musical score for a single instrument written in
I am developing a C++ class library containing domain model classes, and I would
Let's say I have a resource that can have two different behaviors when delete
I've been learning about the Model-View-Controller paradigm (MVC), but I'm quite confused since some
this is the case: ASP.NET MVC C# Model: I would like to use information
If a 32bit Operating System operated with a segmented memory model would their still

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.