Well, I have a question, not a problem.
I have a table in my database, quite small, only 3 columns, but potential for growth. I have two solutions to my problem, but I don’t know why to use them.
I have a piece of data that may or may not already be in the database. Two ways to solve this problem. I have a unique identifier, so it’s easy to verify.
- Check if records exist in the database, and if not,
INSERT INTOdatabase - Use
REPLACE INTObecause I already have an ID.
Now my question. Which one is better to use. What are the pros and cons of using one of the two results. Or is there a better result?
Note. The data is exactly the same, so there is no way for the record to be updated with a newer value. Thus, it REPLACE INTOwill insert data that is already there.
source
share