How can I limit the number of applications per student to 3?

I have one “Students” table and one “Applications” table.
Each student can apply for a maximum of 3 courses. How can I provide this in a database? Call? Constraint?

Can you show me how to write it? I'm new to SQL

+4
source share
2 answers

One way is to put a counter on students. When a line is added to applications, increasing it, when a line is deleted, reduce it. Doing this with triggers is very simple.

Then set the limit for students so that the counter should be <= 3.

+5
source
SELECT COUNT(*) FROM Applications GROUP BY Student_ID 
0
source

Source: https://habr.com/ru/post/1337362/


All Articles