Click here to Skip to main content
12,248,339 members (47,627 online)
Click here to Skip to main content
Add your own
alternative version

Stats

42.5K views
21 bookmarked
Posted

Inserting Bulk Data in SQL Server from Text file

, 1 Jul 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
Inserting Bulk Data in SQL Server from Text file
bulkinsert.JPG

Introduction

This article is simple one for inserting bulk data from text file in to sql server by using a simple query. 

Prerequisite 

SQL Server 2005

Description

Actually in my blog, one guy asked me how to insert bulk data’s in to sql server 2005.  When I tried to answer him I just wrote this article. There is a simple query to do this.

Here with I have given the query for creating a sample table and query for inserting bulk data from text file. 

Query

The query for creating table,
CREATE TABLE Employee
(
 FName varchar (100) NOT NULL,
 LName varchar (100) NOT NULL,
 Email varchar (100) NOT NULL
)


//Then we have a text file with the bulk datas like as follows,
 vinoth,kumar,itvinoth83@gmail.com
emp1FName,emp1LName,emp1@company.com
emp2FName,emp2LName,emp2@company.com
emp3FName,emp3LName,emp3@company.com
emp4FName,emp4LName,emp4@company.com
emp5FName,emp5LName,emp5@company.com
emp6FName,emp6LName,emp6@company.com
emp7FName,emp7LName,emp7@company.com
emp8FName,emp8LName,emp8@company.com
emp9FName,emp9LName,emp9@company.com
emp10FName,emp10LName,emp10@company.com
emp11FName,emp11LName,emp11@company.com
emp12FName,emp12LName,emp12@company.com
//Now the query for inserting bulk data is, 
BULK INSERT Employee FROM 'c:\bulktext.txt' WITH (FIELDTERMINATOR = ',')

//Now you can see the data's inserted in table by the select query as follows,

select * from Employee 

Conclusion

Hence we are inserting the bulk data’s in to sql server by using a simple query. The thing is that we need to keep a formatted text file with appropriate data’s to insert.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

S.Vinothkumar
Web Developer
India India
Hi Viewers,

I wish to all. This is Vinoth. This is where I try to condense everything that you need to know about me.

Blog:

visit my blog

Interests:

I'm passionate about a great many things and continually learning about the things that interest me. They are wearable computers, User Interface Design, Artificial life, Industrial music.






You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 1 Pin
Syed Javed5-Dec-10 2:04
memberSyed Javed5-Dec-10 2:04 
GeneralMy vote of 1 Pin
VMykyt16-Jul-09 21:48
memberVMykyt16-Jul-09 21:48 
GeneralWhats with the "My Vote is 1" remarks. Pin
Shoki3-Jul-09 3:28
memberShoki3-Jul-09 3:28 
GeneralYou Can use DTS. Pin
suresh suthar1-Jul-09 19:48
membersuresh suthar1-Jul-09 19:48 
GeneralMy vote of 1 Pin
suresh suthar1-Jul-09 19:47
membersuresh suthar1-Jul-09 19:47 
GeneralMy vote of 1 Pin
jaan33us1-Jul-09 8:57
memberjaan33us1-Jul-09 8:57 
GeneralMy vote of 1 Pin
Jon Artus1-Jul-09 5:55
memberJon Artus1-Jul-09 5:55 
GeneralMessage Removed Pin
Nejat1-Jul-09 4:27
memberNejat1-Jul-09 4:27 
GeneralCheck into fmt files for more options on bulk uploads Pin
icestatue1-Jul-09 3:30
membericestatue1-Jul-09 3:30 
QuestionRe: Check into fmt files for more options on bulk uploads Pin
searching for solution.....6-May-13 0:28
membersearching for solution.....6-May-13 0:28 
AnswerRe: Check into fmt files for more options on bulk uploads Pin
icestatue7-May-13 4:56
membericestatue7-May-13 4:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 1 Jul 2009
Article Copyright 2009 by S.Vinothkumar
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid