I have a table with 3 columns – id (pk), pageId (fk), name. I have a php script which dumps about 5000 records into the table, with about half being duplicates, with same pageId and name. Combination of pageId and name should be unique. What is the best way to prevent duplicates being saved to the table as I loop through the script in php?
Share
First step would be to set a unique key on the table:
Then you have to decide what you want to do when there’s a duplicate. Should you:
ignore it?
Overwrite the previously entered record?
Update some counter?