How can I limit number of applications per student to 3?
I have one table 'Students' and one table 'Applications'.
Ea开发者_开发问答ch student can apply for max 3 courses. How can I ensure that in database? Trigger? Constraint?Can you show me how to write it? I'm new to SQL
One way is to put a counter on students. When a row is inserted to Applications increment it, when a row is deleted, decrement it. Doing this with triggers is very simple.
Then put a constraint on Students so the counter must be <= 3.
SELECT COUNT(*) FROM Applications GROUP BY Student_ID
精彩评论