title: SQL Server - Update columns in another table
body: <p>I'm very new to triggers and am trying to get to grips with them. I have a database for a sport booking company which includes the tables events, events / bookings and bookings (which contains details of the people who book events). </p>
  
  <p>I want to create a trigger so that when a new event is added to the event table the person in the booking table with the least bookings will add one to their <code>amount_of_bookings</code> column however I'm unsure how to use triggers that change data in a table based on changes made to another table. </p>
  
  <p>Any help would be appreciated. </p>
  
  <p>Thanks</p>
  
  <p>So far I have the following which I am working on:</p>
  
  <pre><code>SET ANSI_NULLS ON
  GO
  
  SET QUOTED_IDENTIFIER ON
  GO
  
  ALTER TRIGGER [dbo].[Test] 
  ON  [dbo].[Event]
  FOR INSERT
  AS 
  BEGIN
      SET NOCOUNT ON;
  
      UPDATE Booking_Coordinators
      SET amount_of_bookings = amount_of_bookings + 1;
  END
  GO
  </code></pre>
  
  <p>Update: I have created a trigger which will add 1 to the amount of bookings column but it does this for every user in the bookings table. I need to change the query so it does it for the user with the least bookings.</p>