SQL Server 2005 中 VARBINARY 字段的大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/507785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 00:59:42  来源:igfitidea点击:

Size of VARBINARY field in SQL Server 2005

sqlsql-serversql-server-2005clr

提问by Tewr

I am trying to determine the size in bytes of the contents in a VARBINARY(MAX)field in SQL Server 2005, using SQL. As I doubt there is native support for this, could it be done using CLR integration? Any ideas would be greatly appreciated.

我正在尝试VARBINARY(MAX)使用 SQL 确定 SQL Server 2005 中字段内容的大小(以字节为单位)。我怀疑是否有对此的本地支持,是否可以使用 CLR 集成来完成?任何想法将不胜感激。

回答by mwigdahl

Actually, you can do this in T-SQL!

实际上,您可以在 T-SQL 中执行此操作!

DATALENGTH(<fieldname>)will work on varbinary(max)fields.

DATALENGTH(<fieldname>)将在varbinary(max)领域工作。

回答by John Sansom

The VARBINARY(MAX) field allocates variable length data up to just under 2GB in size.

VARBINARY(MAX) 字段分配大小不超过 2GB 的可变长度数据。

You can use DATALENGTH() function to determine the length of the column content.

您可以使用 DATALENGTH() 函数来确定列内容的长度。

For example:

例如:

SELECT DATALENGTH(CompanyName), CompanyName
FROM Customers