SQL Server Varbinary(max): select a subset of bytes from the varbinary field

独自空忆成欢 提交于 2019-12-10 02:11:41

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/1288885/sql-server-varbinarymax-select-a-subset-of-bytes-from-the-varbinary-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!