开发者

SQL Server 2005 bulk insert binary types

I have a table in the following format:

smallint, binary(10), smallint, smallint, varbinary(max)

I also have a csv file generated from the data in the table by one of our processes where binary data is exported as hexadecimal data.

I tried generating INSERT INTO statements which worked but was very slow..

I tired BULK INSERT but it is failing and i suspect it is because of the binary data.

Anyone know how can i use BULK INSERT (or something like that ) to insert big amount of data that includes binary data?

A开发者_如何学编程n example of the data:

1,0x00000000000000000BB8,0,142,0x434F4E534E554D424552202020202020040006000600202000000000202000000000000000008000422020202020202020202020202020202020000000000000000000000000000000000000202000000020000000000000000000000000000000000000000000000000000000000200020000000000000004000000E09304006B8016000600FFFFFFFF0B00010007004633303030002E81FFFF1C00FFFFFFFF04001E00

Thanks.


I bet the problem is that 0x434F4E... is being treated as the actual bytes to be inserted (0x3078343334463445) rather than as a hexadecimal expansion. ('0' = 0x30, 'x' = 0x78, '4' = 0x34 and so on.) The truncation would be occurring because hex has two characters per value, so it's trying to insert a string double the length of the one you want.

If you look into the options for BULK INSERT and find no way to tell it to interpret hex as binary, I recommend using SSIS for this. I have no actual experience bulk loading binary values from SSIS, but undoubtedly it can do it, and it will be fast.

I guess there's always the possibility of outputting the actual bytes of the binary values rather than a hexadecimal representation of them, but you're going to run into problems if you're using a delimiter, since the delimiter could be one of the bytes in a binary value. This is exactly the problem of mixing text and binary data. You might be able to do this by using fixed-length column imports, with the special extended syntax for BULK INSERT that defines the columns and their data types.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜