简体   繁体   English

客房预订管理系统数据库设计

[英]Room Booking Management System Database Design

I am developing a DB Design for Conference Meeting Room Booking System. 我正在为会议会议室预订系统开发DB设计。

I am stuck in making Relationship between Rooms & Facilities Entity. 我被困在使房间和设施实体之间建立关系。 There are Facilities (Equipment) like Projector, VoIP, AC etc in each room. 每个房间都有投影机,VoIP,AC等设施(设备)。 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. 示例:如果我搜索具有1个VoIP的会议室,那么我应该得到该会议室;如果我搜索具有3个VoIP和2交流电的会议室,它将显示该会议室。

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. 我想尽量减少使用join。

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). 您应该有一个房间表,其中房间ID为主键(以及其他相关详细信息)。

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. 该表应为每个单独的设备配备一个主键ID,然后具有一个称为RoomId的外键,该外键的值应与与其连接的房间的主键相对应。

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). 每个设施条目都有其自己的ID,带有的roomId与它所属房间的ID(来自Rooms表中的ID)的值相同。

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. 这样,您可以将5个设施连接到一个房间,将4个设施连接到另一个房间,将0个设施连接到另一个房间,将50个设施连接到另一个房间,等等。

In answer to your follow up question about selecting all rooms with for example 2 VOIP facilities: 在回答有关选择具有2个VOIP设施的所有房间的后续问题时:

     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. 该查询将返回一个结果,该结果计算每个房间中有多少个VOIP。 Now throw this in your WHERE in your query. 现在,将其放在查询的WHERE中。

   SELECT * FROM room JOIN facilities ON id = roomId
   WHERE (above query) = 2;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM