SQL Server Storage Engine

Importing UNIX data file

 

When bulk importing data, the data can come from any source including the files created in other operating systems like UNIX. Here are two ways that you can use to bulk import a data file created under UNIX.

 

·         Without using a format file

You can use the following script to bulk load.

 

DECLARE @bulk_cmd varchar(1000)

SET @bulk_cmd = 'BULK INSERT AdventureWorks.Sales.SalesOrderDetail

FROM ''<drive>:\<path>\<filename>''

WITH (ROWTERMINATOR = '''+CHAR(10)+''')'

EXEC (@bulk_cmd)

 

However, the following will not work  because '\n' automatically gets converted to '\r\n' since it's the typical EOF string for Windows text files. The reason that \n works like it does, because we want BCP commands from Unix world on Windows as well

 

bulk insert bcptest

from 'C:\unix\u.dat'

WITH (ROWTERMINATOR='\n')

·         You can use explicit format file with the line terminator character as “\n”

Published Thursday, June 08, 2006 9:59 PM by Sunil Agarwal
Filed under:
Anonymous comments are disabled

About Sunil Agarwal

Sunil Agarwal is a Program Manager in the SQL Server Storage Engine Group at Microsoft. He is responsible for concurrency, indexes, tempdb, LOBS, supportability, and bulk import/export. Prior to joining Microsoft, Sunil worked at DEC, Sybase, BMC Software and DigitalThink, focusing primarily on core database engine technologies and related applications.

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker