Pages

Feb 12, 2008

Importing a Text File into SQL server 2005 programatically using Bulk Insert method

First create a table to which the values from the txt file has to be imported
say we create a table with 2 fields as shown below


create table BULK_INSERTTest
(
LINE_NUM int null,
LINE_DATA VARCHAR(50) null
)


Then using the Bulk Insert command as shown below we can easily import a txt file values
to a table in Sqlserver 2005



BULK INSERT
BULK_INSERTTest
from
'\\ppdys1402\Share\Manual.txt'
WITH
(
FIELDTERMINATOR = '\t',
ROWTERMINATOR = '\n',
FIRSTROW = 2
)

Now view the table using

select *from BULK_INSERTTest

Note:
Here the file that u give should have the access permission to ur account
various constraints like field delimiters , format file , First row etc are there to perform various operations
refer msdn for details

No comments: