1

I am new to mySql and phpmyadmin, I have two tables: the college_building table; this table has the following attributes: id, name, number_of_classes. Then the second table is the classes table; this table has id (auto-incremented) and room_number as attributes, and also the building id as a foreign key.

Is there a way to set a limit for the number of entries in the second table using the auto-incremented id based on the number_of_classes?

For example, if i have a building that has 20 class rooms, I want the classes table to have a maximum of 20 rows.

Alon Eitan
  • 11,997
  • 8
  • 49
  • 58
  • Usually this type of constraint is solved by a unique key constraint that only ever allows one class in one room at a give time to avoid overbooking rooms. – Filburt Apr 14 '19 at 09:18
  • thank you for your reply :) I'm sorry but could u specify to where should I add this constraint? – LearningHowToCodePleaseHelpMe Apr 14 '19 at 10:51
  • [How do I specify unique constraint for multiple columns in MySQL](https://stackoverflow.com/q/635937/205233) should have the answer for that. The interesting problem in your case could be to avoid overlapping but still unique bookings. If you only allow a class for a whole day (or even a whole term) it should be simple enough. – Filburt Apr 14 '19 at 18:00

0 Answers0