For Import Data we need First of All Format File. Format File is a file in which you explain your columns, their data Type and also their delaminate Sign like ‘-’.
After that we have to Create table in sql Server 2008 with respect to format File as describe in following PL-SQL Querry.
Create table Temp
{
[Column1] as Varchar(200),
[Column2] as Varchar(200),
[Column3] as varchar(200),
[Column4] as varchar(200)
}
After that Set each Column Data Type varchar because while importing txt File we don’t want errors related to data type conversions.
So now write the following final Query.
INSERT INTO [tblTemp]
([Column1], [Column2], [Column3], [Column4])
SELECT A.[Column1], A.[Column2], A.[Column3], A.[Column4]
FROM OPENROWSET (BULK 'D:\Test_Data.txt',
FORMATFILE = 'D:\Test_Data.fmt') AS A;