如何使用BCP或Sql Server Management Studio从Sql Server获取BLOB数据?

Eri*_*ric 11 t-sql sql-server blob bcp sql-server-2005

如果已经问过这个问题,我很抱歉,但我无法在任何地方找到它.我有一个表将文件存储为BLOBS.保存文件的列是image数据类型.我希望能够从列中提取二进制数据并将其转换为实际文件.如果可能的话,我希望能够与BCP或管理工作室合作.

我尝试过BCP,但出于某种原因,当我试图拿出一份办公文档时,Word认为它已经腐败了.这是我到目前为止所尝试的(显然已经改变了值以保护无辜:):

bcp "select document_binary_data from database where id = 12345" queryout "c:\filename.doc" -n -S server -U username -P password
Run Code Online (Sandbox Code Playgroud)

这不行吗?有什么想法吗?

编辑结果你不需要-n native flag.此外,BCP尝试在图像列上默认包含4字节前缀 - 您实际上希望此设置为0.

bcp "select document_binary_data from database where id = 12345" queryout "c:\filename.doc" -S server -U username -P password
Run Code Online (Sandbox Code Playgroud)
Enter the file storage type of field document_binary [image]:
Enter prefix-length of field document_binary [4]: 0
Enter length of field document_binary [0]:
Enter field terminator [none]:

Eri*_*ric 25

我正在回答我自己的问题,因为我很生气,告诉我要设置赏金

事实证明你不需要-n native flag.此外,BCP尝试在图像列上默认包含4字节前缀 - 您实际上希望此设置为0.

bcp "select document_binary_data from database where id = 12345" queryout "c:\filename.doc" -S server -U username -P password
Run Code Online (Sandbox Code Playgroud)
Enter the file storage type of field document_binary [image]:
Enter prefix-length of field document_binary [4]: 0
Enter length of field document_binary [0]:
Enter field terminator [none]: