0

I have 2 tables employees and job in a MySQL server. I have 2 CSV files with the same schema as the two tables. Something as below.

Job table(MySQL)

enter image description here

Job(CSV)

enter image description here

Employees(MySQL)

enter image description here

Employees(CSV)

enter image description here

I need to insert the rows from CSV into the MySQL tables. Note that the Id fields in both the tables are on AUTOINCREMENT. I am aware that MySQL does not support merge query and instead has INSERT.. ON DUPLICATE UPDATE. Now the issue with using this is that the Primary keys i.e., the Ids are definitely duplicate but I need them to be inserted as new rows with new Ids. For example, the Admin role should have the Id as 3 and so on. Also, as you can see, the job table is being referenced by the employees table. So the the JobId column in the table should be updated with the respective values. I am not sure how this can be achieved.

Any help appreciated!

Akshatha
  • 592
  • 1
  • 11
  • 28
  • Do you want to import it using mysql or write some kind of program using some programming language. – Nagesh Katke Apr 03 '18 at 05:58
  • I'd prefer it being done with SQL queries and no tools. C# would be okay but like I said, I prefer having queries. – Akshatha Apr 03 '18 at 06:03
  • Then [How to import CSV file to MySQL table](https://stackoverflow.com/questions/3635166/how-to-import-csv-file-to-mysql-table) question might help you – Nagesh Katke Apr 03 '18 at 06:10
  • I don't think it does. The OP wanted to import a single huge file into the table whereas in my case I have foreign-key relationship between the tables. Also I need to insert rows into a table that already holds other rows of data. – Akshatha Apr 03 '18 at 06:18

0 Answers0