drifter Posted December 11, 2006 Share Posted December 11, 2006 I was looking at the "replace into" and I am not sure I get this...I have a tableid (auto increment primary key)useritem (I can make a user/item index that is unique)morefieldsanotherfieldI want to do a replace into. If I doreplace into mytable set user='joe', item='shirt', morefields='red'will this update the row if it exists or create a new one if it doesn't for jack/shirt? Do I not need to know the primary key?ThanksScott Link to comment https://forums.phpfreaks.com/topic/30195-replace-into/ Share on other sites More sharing options...
btherl Posted December 11, 2006 Share Posted December 11, 2006 The documentation is here: http://dev.mysql.com/doc/refman/5.1/en/replace.htmlFrom that page[quote] MySQL uses the following algorithm for REPLACE (and LOAD DATA ... REPLACE): 1.Try to insert the new row into the table 2.While the insertion fails because a duplicate-key error occurs for a primary key or unique index: 1.Delete from the table the conflicting row that has the duplicate key value 2.Try again to insert the new row into the table[/quote]That would indicate that a unique index on the values you want to be unique will have the effect you want, ie it will force replacement rather than creating a new row. Link to comment https://forums.phpfreaks.com/topic/30195-replace-into/#findComment-138855 Share on other sites More sharing options...
drifter Posted December 11, 2006 Author Share Posted December 11, 2006 thanks for the clarification Link to comment https://forums.phpfreaks.com/topic/30195-replace-into/#findComment-138860 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.