Sunday, 16 October 2016

How to insert bulk of records from a text file in SQL-Server

In this article, I will explain you how to insert bulk of records from a text file in SQL-Server table. Below is the step to insert bulk of records into a table. Bulk insert is supported from SQL-Server 2008.

Creating a Text File

Create a text file with name Employee.txt. Add below data and save it on hard drive.

1,John,Male
2,Mary,Female
3,Rahul,Male
4,Mathew,Male

Using Bulk Insert

I am using temporary table to insert records. First create a temporary table #Employee. Second step is to load data from a text file using bulk insert command. Fieldterminator is used to specify the delimiter to separate column values.

create table #Employee
(
 Id int,
 Name varchar(20),
 Gender varchar(10)
 )

bulk insert #Employee from 'E:Employee.txt' with (fieldterminator = ',')

select * from #Employee

drop table #Employee
Share:

0 comments:

Post a Comment

Email Subscription

Subscribe to our newsletter to get the latest articles directly into your inbox

Blog Archive

BUY FROM AMAZON