SQL Trigger to update another table

I have a Maximo database that has a table structure that I cannot change. I am looking to copy the primary email address to the PERSON table anytime it is created or updated. The following structure describes the PERSON table and the EMAIL table


PERSON table:

PERSONID | EMAIL | ...(other irrelevant columns)...

EMAIL table:

PERSONID | EMAILADDRESS | ISPRIMARY | ...(other irrelevant columns)...

As you can see, the two tables are linked in the PERSONID column. Here is what I would like to do with the trigger:
If the EMAIL table is updated or a new row is inserted, I would like to copy the EMAILADDRESS field to the corresponding record (as indicated by PERSONID) in the PERSON table, if the ISPRIMARY field is 1 (1 means primary , 0 means secondary).
I have not written many triggers, so I want to make sure that I only look at the rows that are updated or inserted into the EMAIL table, and only update the PERSON table if there is a new / updated primary email address. Thank you in advance for your help!


UPDATE 1:
After looking at Cade's answer, here is the trigger that I am starting to shape:

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  

, , - .

+3
1

EMAIL. .

, , , , PERSON?

, , , , . , , , NULL.

CREATE TRIGGER EMAIL_update ON UPDATE
AS
BEGIN
    UPDATE PERSON
    SET EMAIL = i.EMAILADDRESS    
    FROM PERSON
    INNER JOIN inserted AS i
        ON i.PERSONID = PERSON.PERSONID
    INNER JOIN deleted AS d -- could try changing this to a left join and use same trigger for INSERT
        ON -- what? could use PERSONID, but it not unique
    WHERE i.ISPRIMARY = 1 -- This helps with uniqueness, but what about things leaving primary?
    -- AND i.EMAILADDRESS <> PERSON.EMAIL -- Could add this (what about NULLs?)
END
+4

Source: https://habr.com/ru/post/1783287/


All Articles