RSS

Bulk insert In SQL Server

05 Feb

/*

Bulk insert And OPENROWEST

*/

http://msdn.microsoft.com/en-us/library/aa225968(v=sql.80).aspx

—————————*******************Bulk Insert******************—————————–

–Step 1 Create Table [CSVTest]

CREATE

TABLE [dbo].[CSVTest]

(

[ID] [int]

NULL,

[FirstName] [varchar]

(40)COLLATE Arabic_CI_AS NULL,

[LastName] [varchar]

(40)COLLATE Arabic_CI_AS NULL,

[nvarchar]

(50)COLLATE Arabic_CI_AS NULL

—Step 2 Create Text File on D:\ Location

—Step 3 Try Bulk Insert

go

BULK

INSERT

[CSVTest]

FROM

‘D:\TxtFile2.txt’

WITH

(

BATCHSIZE

= 2,—- Show The Rows Affected

FIRSTROW

= 2,—– Start the insert from Row number 2

FIELDTERMINATOR

=‘,’,

ROWTERMINATOR

=‘\n’,

LASTROW

= 4,—- End the insert when you Arraive to row number 4

MAXERRORS

= 1 — Number of errors After this Number The SQL not complete the insert the defult value is 10

)

GO

–Step No 4 Check the Data inserted

Select

*from [CSVTest]

Delete

from [CSVTest]

Drop

Table [CSVTest]

 
Leave a comment

Posted by on February 5, 2012 in Script

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s