SQL Server: Tips and Tricks - 2 (2017)

How to generate Insert Statements from Text Files for SQL Server Table in SQL Server


You are working as SQL Server developer, you get text files such as comma separate values, Tab delimited or pipe delimited files. It is one time task and you need to generate insert statements from these files so you can load the data into dbo.Customer table in DEV, QA, UAT and Production environments by using those scripts.

If you have tab delimited or pipe delimited file, first of all we need to open with excel and then use the formulas.

Step 1:
Let's say that I have Tab delimited Customer.txt file as shown below and want to open in excel.


Step 2:
Open Excel and then go to File and hit Open, Browse to customer.txt file


Test Import Wizard will open, Choose Delimited and Click My Data has Headers if it does and then Click Next


Choose the Delimiters, in our case it is Tab and hit Next.



Once you will hit Finish, below excel sheet will be populated with flat file data.


More to Come

Write a short review at the site you purchased Email me at sales@meetcoogle.com with a link to your review and I’ll reply with series next book for free!