Quickest way to Update or Insert?

I have a Database Update query to update a persons record. I have a phone number that I want to Update or Insert, so straight after the first Update I want a Database Update sub-query that writes a phone number to a second table related to the first (this allows many phone numbers for one person). I don’t know if the phone number already exists in the second table and so I don’t know if I need an Update or an Insert. The second table uses the first table’s ID as a foreign key.

Is this the right way to do this?

DB Connection
Database Update: people_update [Table 1 : updates the person’s record]
Database Query: people_contact_numbers [Table 2 : looks for person’s matching phone number]
~> Condition [Does number exist in people_contact_numbers ?]
~> Then
~> ~> Update
~> Else
~> ~> Insert

in other words do I have to query the second table and then do a condition?

Community Page
Last updated: