Prepare SQL insert Query in Excel

Sometimes when you want to insert data into SQL database which is already in excel, inserting records one by one can be cumbersome.

This also applies when you want to update statements in SQL database which is in excel

Luckily you can generate SQL insert / update statements which you can later execute on the database console.

Below is the tutorial that will guide you to generate SQL statements in excel.

The example below shows a simple insert statement prepared from sales data in a table. But you can easily extend this method to prepare complex query statements depending on your data.

My data in excel is arranged like this

Excel data

Important to note: The order and number of columns need to match your SQL data table

Once the data is ready it is very easy to generate the SQL queries using excel string addition operator – &.

The final prepared queries will look like:

sql queries


You can now copy the query in your SQL database  console

 Formula: = “insert into customers values(‘” & A2 & “‘,'”&B2&”‘,'” &C2 &”‘,'” &D2 & “‘,'”&E2&”);”

Leave a Reply

Your email address will not be published. Required fields are marked *