Database Design – How to Model Weak Entity in ER Diagram

database-designerd

I was going through the weak entity concepts and was trying to model the relation Hotel has many rooms. I have come up with the partial solution presented below but i'm having a problem to uniquely identify the tuples in the room entity related to the specific hotel.

My Assumption

  1. Hotel(hotel_number, name) is a strong entity.
  2. Rooms(room_number, bed) is a weak entity whose existence depends on the existence of the hotel.

Modeled ER Diagram

1. Hotel entity's table

hotel_id name
125 n1
132 n2
173 n3
103 n4
193 n5

2. Room entity's table

room_number beds
101 3
101 2
102 1
103 6

There are two hotels with hotel_id 125 and 132. Hotel with hotel_id 125 has room numbered 101 with 3 beds and another hotel has room_number 101 with 2 beds. So how can i model the given relation in such condition as there's no pk for the weak entity i.e. room ??

Best Answer

Room should have PK of (hotel_id,room_number).

Weak entities have compound keys with the strong entity key/foreign key as the leading column(s).

There are people who disagree with this approach, but they are wrong.

How can i find the room belonging to specific hotel which has the different number of beds limiting the attributes in the domain of my problem

Something like:

select *
from rooms
where hotel_id  = 1001
  and beds = 3