I am a database beginner, I met a problem during my study.
I am now going to update one table of my database by importing a text file through phpMyAdmin.
Everything worked great except for handling with rows that has same customer_ID.
The row has a field called “customer_ID”, and I cannot make this a primary key, since the initial text file used to populate the database contains multiple rows for a single customer_ID, so database must allow multiple rows for one user id.
I populated the database with the import text file, no error. However, now I need to update the database with an update text file, the customer_id within the update text file are all already existed(populated) in the database, so if I update the database with this updated text file(through the “import” function in PhpMyAdmin), the existing rows with the same customer_ID will not be updated, but another row with the same customer_ID will be created, which is not exactly what I want.
I think this is a dilemma, if I could make the customer_id a primary key, the update process will work perfectly, but since I need to allow customer_id appearing in multiple rows in the database populating process, so I couldn’t make customer_id a primary key.
Please pardon for the trivial question.I wonder if experts could give me some suggestion or some related readings? Thanks in advance for the help.
You need to make your update file follow this sort of format:
However where you have multiple rows with the same customer id that will update all the rows, which is probably not what you want. So you need another id field (as Ray says), which is unique, and update using that id