Inserting with a Unique Index
suggest changeUPDATE Customers SET Email = 'richard0123@example.com' WHERE id = 1;
This fails if a unique index is set on the Email column of Customers and another row already has that address. ON DUPLICATE KEY is not valid on UPDATE. In MySQL it is an INSERT clause, and it requires an update assignment:
INSERT INTO Customers (id, Email)
VALUES (1, 'richard0123@example.com')
ON DUPLICATE KEY UPDATE Email = VALUES(Email);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents