View Single Post
Old 09-04-2008, 11:38 PM  
fluffygrrl
So Fucking Banned
 
Join Date: May 2006
Posts: 2,187
Quote:
Originally Posted by acctman View Post
does it matter if i use Update to insert new data into mysql or should I always use INSERT for new data and UPDATE for changing?
This depends on what exactly you're trying to accomplish and how.

Off the top of my head, INSERT allows for ON DUPLICATE KEY UPDATE, which can also use a compound (unique) key to check for duplication. This is very userful. For example:
If you have a log table to log hits to different websites daily, with "site_id"-s and "time" fields, where neither of them are primary keys, but togethether they are unique, then you can create a key on them, and then use "...ON DUPLICATE KEY..."

There's also the issue of permissions, where UPDATE only requires UPDATE priviledges whereas INSERT requires both INSERT and UPDATE, which might or might not be an issue.

I'm sure there's more.
fluffygrrl is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote