In MySQL, in which cases should I use REPLACE and in which ones should I use UPDATE. Adding to this as a bonus, in what cases should I use a combination of DELETE and then INSERT in comparison to the 2 first mentioned.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You use REPLACE when you are not sure if a record exists in your database or if you do not want to check if it exists. Basically what will happen is if the record exists it will be deleted and inserted, if it does not it will be inserted. It’s there mostly for convenience but is not ANSI SQL.
It’s generally better for performance to do an UPDATE vs a DELETE/INSERT. So it’s generally discouraged to use REPLACE.
Your preference should always be