I’m working in MySQL and PHP. How in MySQL do you do an update to an existing table with additional records, without causing duplicates? The records are customers and the key to each record is the customer account number such as “1234”.
I need to do basically three things. Add a new customer record if their customer account doesn’t exist, update an existing customer’s information such as their phone number or e-mail address has changed, or delete the customer record if they are no longer a customer.
The data comes in as a feed daily, and marketing wants to have their own data base of customers with their own fields added, which is why I don’t simply re-create the database from the daily feed. The goal is to keep it up to date with the feed. Thanks!
I would suggest that you do all of the processing using PHP.
When you’re looping through your customer records, first check if the record exists:
Alternatively, you could do one select query to get the customer account numbers and pop them in an Array.
Also, as suggested by Tadman, if you make sure the customer account number is a UNIQUE column then that will add extra protection to make sure duplicates can’t be added.