'How to create database taking Students meal attendance taking

I am trying to create student meal attendance system for like school/university/college. And the system will include this:-

Students can eat 3 time a day (breakfast, lunch and dinner) but they can't eat breakfast or any other meal more than once.

I was trying to create it like this but I don't know how to restrict them can anyone help.

Students

Id Name
Stud12 Abebe

Meal

Id Name
1 Breakfast
2 Lunch
3 Dinner

Meal Attendance

Id Stud_id Meal_id Date Status
1 Stud12 1 03-04-2021 1


Solution 1:[1]

You can check before insert to MealAttendance

Example:

SELECT EXISTS(SELECT * FROM MealAttendance WHERE Meal_id = 1 and Stud_id = 1 and Date = '03-04-2021')

If the row exists, you can restrict.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Maruf