MySQL

When UPDATE Doesn't

Several months ago I became aware of the ON DUPLICATE KEY UPDATE clause of the INSERT MySQL command. This meant that I could use a single command to insert and/or update a database record, without any additional code to determine whether or not I needed to INSERT or UPDATE. Couple that with the ON UPDATE CURRENT_TIMESTAMP option for a timestamp field and I can turn this:

~~~