数据库
首页 > 数据库> > linux – 为什么sqlcmd会截断varbinary(max)?

linux – 为什么sqlcmd会截断varbinary(max)?

作者:互联网

在sys.assembly_files目录中,我可以看到一个名为content的字段

1> SELECT assembly_id, LEFT(name, 50), file_id, content FROM sys.assembly_files;
2> GO
assembly_id                                                    file_id     content
----------- -------------------------------------------------- ----------- -------
          1 microsoft.sqlserver.types.dll                                1 0x4D5A90x07585

(1 rows affected)

但是,即使使用sqlcmd -Y 8000 -y 5000我也不能超过0x4D5A90x075850x167D00x043CB

assembly_id                                                    file_id     content
----------- -------------------------------------------------- ----------- -------
          1 microsoft.sqlserver.types.dll                                1 0x4D5A90x075850x167D00x043CB

想知道发生了什么,并怀疑客户端没有将一切都归还给我,我尝试了mssql-cli,pg-cli到SQL Server的端口.使用mssql-cli,我看到了整个内容字段,实际上看起来是正确的大小是位内容.这让我相信这是sqlcmd.exe截断,或其他毁坏和掺杂程序集的字节码表示的问题.使用mssql-cli,我得到了这个

master>SELECT assembly_id, LEFT(name, 50), file_id, content FROM sys.assembly_files;
...... 
-[ RECORD 1 ]-------------------------
assembly_id      | 1
(No column name) | microsoft.sqlserver.types.dll
file_id          | 1
content          | 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000D00000000E1FBA0E00B409CD21B........ and on and on
(1 row affected)

解决方法:

Why does sqlcmd truncate varbinary(max)?

因为它可能是GB的数据,所以像SQLCMD和SSMS这样的查询工具会截断显示的结果.

您可以使用bcp.exe转储到文件,将“prefix-length”设置为0.

bcp "select content from sys.assembly_files where name = 'microsoft.sqlserver.types.dll'" queryout microsoft.sqlserver.types.dll -T

Enter the file storage type of field content [varbinary(max)]:
Enter prefix-length of field content [8]: 0
Enter length of field content [0]:
Enter field terminator [none]:

Do you want to save this format information in a file? [Y/n] n

Starting copy...

1 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total     : 62     Average : (16.13 rows per sec.)

标签:sql-server-2017,linux,sqlcmd,system-tables
来源: https://codeday.me/bug/20190807/1606924.html