so MYSQL’s REPLACE command (not to be confused with the string replace function) replaces a row if there exist a column with the same primary key with the inserted data…
but what if I have two primary keys and I want to use both to specify the row to replace not just one of them….how do I specify mysql to use both keys rather than just one
It shouldn’t make a difference, it’s the same syntax. Just be sure you have both keys specified as columns. For example:
EDIT
Here’s my test I ran in my test database to make sure I wasn’t about to destroy your data. Of course, I encourage you to try it out if you’re unsure!
This is my result:
ANOTHER EDIT
I think I see what you’re talking about in the documentation, the confusion over unique columns:
That’s referring to a rather contrived circumstance in which the row you’re replacing with conflicts not just with an existing primary key, but with other unique columns as well. Here’s another example to illustrate this point:
Notice how the last REPLACE operation not only conflicts with the (
key1,key2) primary key, of the first REPLACE, but also with the unique color of the second one. In this case, BOTH rows are deleted before the last REPLACE operation is performed so that the result is no conflict. You’ll end up with just two rows:Both the row with (
key1,key2) equal to (‘widgets’, 14) AND the row with the color ‘yellow’ were blown away due to the new row conflicting with multiple unique constraints on the table.Hope this helps!