user1556695
user1556695

Reputation: 85

Mysql REPLACE not working

For some reason my script isn't deleting existing rows when I'm using replace.

I'm working on an inventory management system, and I may be calling this script every hour or so to update the db:

   REPLACE INTO inventory(username, sku,asin,set_price,inventory)
                   VALUES('trav','AEG5502','B00875JE0C','23.49','');

but instead of deleting the old row, it creates a new row with the exact same info.

I'm sure it's a simple error, but I would love if someone could help me out.

Additional info, a row has about 15 columns. None of these columns (username, sku,asin,set_price,inventory) are a primary key, I don't know if that has to be the case for replace to work, but I thought I'd mention it.

Thanks

Upvotes: 2

Views: 6033

Answers (1)

Marc B
Marc B

Reputation: 360872

RTLM: http://dev.mysql.com/doc/refman/5.0/en/replace.html replace will only replace if ANY of the fields you're using are the primary or at least a unique key in the table. since none of your fields are, it simply does an insert

Upvotes: 4

Related Questions