I would like to import data from a text file to my database, but I want mysql to only update the record if it finds a match with one of the table fields or else it should add a new record to the table. Can I do this with mysql.
Thanks
Printable View
I would like to import data from a text file to my database, but I want mysql to only update the record if it finds a match with one of the table fields or else it should add a new record to the table. Can I do this with mysql.
Thanks
The process that you describe will require a custom application or script written in a language that can interface with your mysql database. A language such as Python, PHP, Perl or Java would be ideal for creating such a program. What programming languages are you familiar with?
- Marshall
I work with Perl and some PHP.
This is what your application needs to do:
o Read in the text file line by line.
o Use a SELECT statement based on values in that line to see if the record already exists in your database.
If it exists, use UPDATE to modify it with the new values.
If it doesn't exist, use INSERT to create the new record.
If you need assistance with the coding, choose the language that you'd like to use and post a message to the appropriate language forum.
G'Luck,
- Marshall