SQL Server Varbinary(max):从 varbinary 字段中选择字节子集

发布于 2024-08-02 12:17:13 字数 326 浏览 3 评论 0原文

在 SQL Server 2008 中从 varbinary(MAX) 字段(不使用 FileStreams)读取部分二进制数据的最有效方法是什么?

将数据写入列时,T-SQL 中提供了 VarBinary.Write() 函数,允许将字节增量写入字段,但似乎没有类似的函数可用于读取数据。

我知道 .Net 中的 DataReader.GetBytes() 方法只会选择您要求的字节,但这会带来性能开销吗?也就是说,sqlserver 中的 select 会读取数据库中的所有字节,然后为 getBytes() 方法提供所有这些字节,以便它获取从它们请求的字节子集吗?

感谢您的任何帮助。

What is the most efficient way of reading just part of the binary data from a varbinary(MAX) field (not using FileStreams) in SQL Server 2008?

When writing data to the column the VarBinary.Write() function is available in T-SQL, allowing bytes to be written to the field incrementally, but there doesn't appear to be a similar function available for reading data.

I know of the DataReader.GetBytes() method in .Net which will select just the bytes you ask for, but does this carry a performance overhead with it? i.e. will the select in sqlserver read all of the bytes in the database, and then give the getBytes() method all of these bytes for it to take the subset of bytes requested from them?

Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小糖芽 2024-08-09 12:17:13

您使用SUBSTRING。这会从服务器上的 varbinary 数据中读取一个片段,并且仅将该片段返回给客户端。

[SUBSTRING] 返回 SQL Server 中字符、二进制、文本或图像表达式的一部分。[it] 如果表达式是受支持的二进制数据类型之一,则返回二进制数据。字符串与指定表达式的类型相同,但表中显示的例外情况除外。

You use SUBSTRING. This reads a snippet from your varbinary data on the server, and only returns the snippet to the client.

[SUBSTRING] Returns part of a character, binary, text, or image expression in SQL Server.. [it] Returns binary data if expression is one of the supported binary data types. The returned string is the same type as the specified expression with the exceptions shown in the table.

一个人的旅程 2024-08-09 12:17:13

据我所知,使用 DataReader.GetBytes() 是可以没有开销的。但您必须使用 CommandBehavior.SequentialAccess 选项调用 ExecuteReader()

Using DataReader.GetBytes() is possible without overhead, afaik. But you'll have to call the ExecuteReader() with the CommandBehavior.SequentialAccess option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文