Question : Insert on duplicate key MySQL question

I have a question about the INSERT ... ON DUPLICATE KEY UPDATE syntax - is there a way to call this that actually replaces the row with a matching primary key in a table with an AUTO_INCREMENT set on the primary key column? Right now I have a structure like this (id is the primary key):

+----+----------------+--------------+
| id   | fileSystemId  | notes          |
+----+----------------+--------------+
|  1   | 550               | File Notes   |
+----+----------------+--------------+

When I call this query:
INSERT INTO tbFileNotes (fileSystemId, notes)
VALUES (550,'Notes Update')
ON DUPLICATE KEY UPDATE notes='Notes Update'

I'm expecting that it would simply update the notes column with the new value, but instead its creating a new row with the new notes value. Is there a way to simply make it replace? I used the REPLACE syntax as well but it does the same thing, leading me to believe there is an issue with AUTO_INCREMENT.

Thanks in advance.
Steve

Answer : Insert on duplicate key MySQL question

For it to work, you need to have an UNIQUE index on the `fileSystemId` field. If the index on that field is not UNIQUE it will not qualify for the DUPLICATE KEY event...
Random Solutions  
 
programming4us programming4us