Page 1 of 1

INSERT UPDATE AUTO_INCREMENT ON DUPLICATE KEY

Posted: Wed Oct 12, 2005 9:48 am
by kendall
i am building a csv import method that will upload a csv formatted file that inserts NEW data into the resepective table.

Now firstly i had the method insert data that had manual inputs auto_incremented ids. The problem with this was that the person had to know what was the last id inserted. Thus when the data was importing they got 'Duplicate Id' errors.

So now i am having auto_incremented ids created dynamically by mysql eliminating the use of auto_incremented ids manual inputted into the csv data.

This creates another issue as i would not be able to detect entries that may already exits in a row.

I thought first of having to do a SELECT to detect this b4 i INSERT but it proves to be 2 tedious

SO i looked up the INSERT...ON DUPLICATE KEY UPDATE. I have not implemented it yet but what i cant understand about its definition is that if it works on only the PRIMARY KEY or on a COLUMN DATA = DATA condition (im using MySQL 4). I am hoping that this relieves my problem but i woould also need it to both UPDATE where the primary key matches and also if the cloumn data matches.

should i be looking into a UPDATE methodology rather than an INSERT?

Kendall