I have a table, I named 'srcCodDsc', that has 3 column:
- ID : INT PRIMARY KEY with AUTO_INCREMENT
- locId : VARCHAR
- locDsc : VARCHAR
I also defined an unique index on locId, to avoid duplication of a locId value.
Now the problem :
INSERT INTO srcCodDsc (locId,locDsc) VALUES ('012_002','value to set')
ON DUPLICATE KEY UPDATE locDsc=VALUES(locDsc);
The query update correctly the locDsc value of the row with locId = '012_002', but I discover that the AUTO_INCREMENT next value counter is incremented at every execution of the query, even if a new line is not inserted.
I check it with command:
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='berna' AND TABLE_NAME='srcCodDsc';
How to turn the query into a conditional form that, after checking if the record with locId = '012_002' exists, in one case does insert, in the other one does update and if locDsc is already worth the new value does nothing?
NOTE: the same query in mySql works and not update auto_increment next value.
Thank you