Generate insert SQL statements from a CSV file

It’s a bit crude – but for one off jobs, I sometimes use Excel.

If you import the CSV file into Excel, you can create a formula which creates an INSERT statement by using string concatenation in the formula. So – if your CSV file has 3 columns that appear in columns A, B, and C in Excel, you could write a formula like…

="INSERT INTO MyTable (Col1, Col2, Col3) VALUES (" & A1 & ", " & B1 & ", " & C1 & ")"

Then you can replicate the formula down all of your rows, and copy, and paste the answer into a text file to run against your database.

Like I say – it’s crude – but it can be quite a ‘quick and dirty’ way of getting a job done!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)