I am developing a DB Design for Conference Meeting Room Booking System.
I am stuck in making Relationship between Rooms & Facilities Entity. There are Facilities (Equipment) like Projector, VoIP, AC etc in each room. How to assign total no. of each equipment per room ?
Example : If I search for Room with 1 VoIP then I should get that Room & If I search for Room with 3 VoIP & 2 AC it will display that room.
Current DB Design
Room ID Room Name Facility ID
1. R1 11
2. R2 14
Facility ID AC VoIP Projector
11. 1 3 1
12. 2 1 0
Please help me to make it better. I want to use join less as much as possible.
Any Help would be appreciated...!!!
I think what you want is a many to one relationship or a "has many". Without typing out your code for you I will give you the basic design concept:
You should have a table for rooms with an id as a primary key(and other relevant details).
For example Rooms:
id
roomName
otherData
Use a second table for facilities. This table should have a primary key id for each individual piece of equipment and then a foreign key called RoomId which will have the value that corresponds to the primary key for the room it is connected with.
Facilities:
Id
roomId
name
cost
otherData
Each facilities entry will have its own id, a roomId with will be the same value as the id for the room it belongs to(the id from the rooms table).
This way you can have 5 facilities connected to one room, 4 connected to another, zero connected to another 50 connected to another one etc.
In answer to your follow up question about selecting all rooms with for example 2 VOIP facilities:
SELECT Count(name) FROM facilities WHERE name = "VOIP" GROUP BY roomID
This query will return a result that counts how many VOIPs are in each room. Now throw this in your WHERE in your query.
SELECT * FROM room JOIN facilities ON id = roomId
WHERE (above query) = 2;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.