简体   繁体   中英

if i have main room and spare room should they be in different tables?

I am developing a database for a college.

The system should select a room for each course after considering day, time and number of seats.

The college has specific rooms in specific buildings for specific majors.

For example: Computer Science is in building #1 and it has rooms 1001-1010. Business is in building #2 and it has rooms 1001-1020.

In some situations (for example all rooms are busy in specific time...etc) then other rooms 2001-2003 in building #2 will be used for Computer Science.

I am not sure if I should create a table for main room and another for spare room or they should be in one table.

Note : later the system should print the course name, times, room number and in which building.

part of ER diagram

I think you need something like this. There may be more fields required but these are the essentials to solve your basic problem.

I have assumed that each room can occasionally be used by more than one major, If that's not true, you could use a slightly simpler design.


"Major" table (eg computer science, business)

Fields:

"MajorID"

"Name"


"Course" table (eg some course within a major)

Fields:

"CourseID"

"Name"

"MajorID" - foreign key to Major table


"Buildings" table

Fields:

"BuildingID"

"Name"


"Rooms" table

Fields:

"RoomID"

"Name"

"Capacity" (number of seats)

"BuildingID" - foreign key to Buildings table


"AvailableRooms" table. This will define which rooms can be used for which majors when allocating space to a course. Don't get hung up on the idea that each major only uses a specific building. As you pointed out, in reality they don't, because they have extra rooms in other buildings.

Fields:

"MajorID" - foreign key to Majors table

"RoomID" - foreign key to Room table

"Spare" - you can use this as a boolean to indicate whether this is a "spare" room or not. Then your algorithm can take this into account and only choose these rooms if no regular rooms are available for the major that the course is associated with.


"CourseRoomAllocation" - this is where your allocation algorithm will record which rooms are actually allocated to which courses, at which times. This might get more complicated but the basics would be like this:

Fields:

"RoomID" - foreign key to Room table

"CourseID" - foreign key to Course table

"BookingStart" start date/time of usage

"BookingEnd" end date/time of usage


I imagine the reality will inevitably be a bit more complex than that, but I think that should be more than enough to get you started.

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.

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