title: SQL Trigger to update another table
body: <p>I have a Maximo database that has a table structure I cannot change. I am looking to copy the primary email address into the PERSON table anytime it is created or updated. The following structure describes the PERSON table and EMAIL table</p>
  
  <hr>
  
  <p>PERSON table:</p>
  
  <pre><code>PERSONID | EMAIL | ...(other irrelevant columns)...
  </code></pre>
  
  <p>EMAIL table:</p>
  
  <pre><code>PERSONID | EMAILADDRESS | ISPRIMARY | ...(other irrelevant columns)...
  </code></pre>
  
  <hr>
  
  <p>As you can see, the two tables are linked on the PERSONID column. Here is what I would like the trigger to do:<br>
  If the EMAIL table is updated or a new row is inserted, I would like to copy the EMAILADDRESS field to the corresponding entry (as linked by PERSONID) on the PERSON table IF the ISPRIMARY field is equal to 1 (1 means primary, 0 means secondary).<br>
  I have not written many triggers so I want to make sure I am only looking at the rows that are being updated or inserted into the EMAIL table and only updating the PERSON table if there is a new/updated primary email address. Thanks in advance for all of your help! </p>
  
  <hr>
  
  <p>UPDATE 1:<br>
  After looking at Cade's response, here is the trigger I am beginning to form:</p>
  
  <pre><code>CREATE TRIGGER EMAIL_update ON UPDATE,INSERT  AS  BEGIN      
  UPDATE p  
  SET p.email = i.emailaddress
  FROM dbo.PERSON as p
  INNER JOIN inserted AS i ON i.PERSONID = p.PERSONID AND i.isprimary=1 
  END  
  </code></pre>
  
  <p>I believe that trigger should work anytime something is updated OR inserted to the email table. </p>