In this article, I will explain you inserting Bulk of records from a text file in SQL-Server. 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 file 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