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
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论