I am attempting to import data into a table that has a field as follows:
result_id
This field is set to AUTO_INCREMENT
, PRIMARY
and UNIQUE
.
The data I am importing has information in the result_id
field that is the same (in places) as the current data in the table. SQL won't let me import as there are duplicates (which is fair enough).
Is there a way to get SQL to append the data I am importing and not use the duplicate data in result_id
, basically to continue the number within the SQL field. The reason I am asking is that I am importing about 25,000 records and I don't want to manually have to remove or alter the result_id
information from the data being imported.
Thanks,
H.
How are you importing your data to MySQL?
If you are using SQL queries/script, then there should be something like INSERT INTO...
. Open the file in some text editor and replace all INSERT
by INSERT IGNORE
. This will ignore inserting rows with duplicate primary keys.
Or alternatively if you want to replace older data with same primary keys to that in your import script, then simply use REPLACE
query in place of INSERT
query.
Hope it helps...
[EDIT]
Since you have Primary key, auto increment. In your table in which you want to import data, add a dummy column say "dummy" and allow it to be NULL. Now, in your import script there will be statement like INSERT INTO () values (). Now in the list of column names replace "result_id" by "dummy" and execute the script. After executing script simply remove "dummy" column from table. Though it is bit dirty and time consuming but will do your work.