INSERT ... ON DUPLICATE KEY UPDATE

The other day I found out about MySQL's INSERT ... ON DUPLICATE KEY UPDATE statement. It allows you do do an INSERT when a given key doesn't exist, or to do an UPDATE statement when it does.

I have a lot of code that does a query to see if the given ID exists, and then does an INSERT or UPDATE depending on the condition. This statement should simplify such code nicely. Good thing I know about it now.

I'm not sure if this is MySQL specific or general SQL. I'm pretty firmly locked into MySQL already though, so it doesn't really matter to me.

Posted by dustin on March 6, 2006 with category tags of

1 comment
NEEd INSERT ON DUPLICATE KEY UPDATE
   comment by prasad on April 20, 2006

Commenting is currently off. You can email the author.

   

VorgTag CloudArchives

Written by dustin
Photo Showcase
Quote Showcase

Friends of Vorg
Computer Games
Popular Posts

Hey You! Subscribe to dustin's RSS feed.
Or get wider opinion in the Vorg All Author feed.

 
 

Members login here.
© Vorg Group.