.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> DataBase >> Post New Resource Bookmark and Share   

 Subscribe to Articles

BULK INSERT in to SQL SERVER (Insert data from file to SQL SERVER)

Posted By:shiv chandra       Posted Date: June 12, 2011    Points: 200    Category: DataBase    URL: http://www.dotnetspark.com  

BULK INSERT in to SQL SERVER. Insert data from file to SQL SERVER separated by Row and Field delimiter.
 

Step 1: Create Table.
-- Create Table
CREATE TABLE [dbo].[BulkInsertTest](
	[Name] [varchar](255) NOT NULL,
	[Sallary] [numeric](18, 0) NOT NULL
)

Step 2: Check for Data
-- Select Data from Table (No data)
Select * from  BulkInsertTest
Output of step-2:



Step 3: Its time to insert Bulk Data.
-- Execute bulk insert query
BULK INSERT BulkInsertTest
FROM 'C:\BulkInsertData.txt'
WITH
(
	FieldTerminator = ',',
	RowTerminator = '\n'
)
GO
Screen shot of data in File (C:\BulkInsertData.txt).


Step 4: Check for data
-- Check for records (now it contains 5 records that are inserted through BULK INSERT) 
Select * from  BulkInsertTest
Output of Step 4:


Step 5: Remove Table.
-- DROP Table
DROP TABLE [dbo].[BulkInsertTest]
Click to download whole script.

Regards,
Shiva

 Subscribe to Articles

     

Further Readings:

Responses
Author: Vilas Gite         Company URL: http://www.dotnetspark.com
Posted Date: June 21, 2011

bulk insertion could not work in SQL Server 2005?

Msg 4860, Level 16, State 1, Line 1
Cannot bulk load. The file "C:\sample_insert.txt" does not exist.

Author: shiv chandra         Company URL: http://www.dotnetspark.com
Posted Date: June 21, 2011

Hi Vilas,
For that you need to create file named sample_insert.txt in C:
Error is because file can not be found.

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend