question

To-007 avatar image
To-007 asked

how to create a trigger on sql server

Apologies in advance as I am new to triggers - I need to write a trigger to restrict a tutor from tutoring students from 5 different locations:

<code>TutorName   StudentName LocationID 
----------------------------------
Tom         Harry    1 
Tom         Lima     1       
Tom         Liam     2     
Tom         Greg     3
Tom         Bill     3
Tom         Bob      3    
Tom         Lare     4
Tom         Phill    4    
Tom         Hassan   5
Tom         Nichole  5
Tom         Levi     5

Tutor Tom can tutor a maximum of 5 groups of students from 5 different locations.

I need a trigger that will STOP Tom from teaching students from a different location as he is already teaching students from 5 locations EG: if he tries to teach someone from location 6 (East London) the trigger will stop this.

<code>LocationID Location Name
------------------------1          North East
2          North
3          South East 
4          South West
5          West
6          East

not sure how to approach this as it seems very tricky - I can't do a simple count because the number of students can be anything up (1-5). Will I need an insert and update trigger? Please could someone help? :)

sqlsql-server-2012triggersqlservertriggers
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.