sql-server – 更新VARBINARY(max)列时.WRITE(NULL,NULL,NULL)的语义

以下查询的语义是什么?

UPDATE table
SET column .WRITE(NULL, NULL, NULL)

如果列是VARBINARY(max)类型且其内容不是NULL?

快速测试表明该查询
是一个无操作:

--DROP TABLE [table]
CREATE TABLE [table] ([column] VARBINARY(max))
INSERT INTO [table] VALUES (0x12345678)
UPDATE [table]
SET [column] .WRITE(NULL, NULL, NULL)
SELECT * FROM [table]

执行它不会改变列中的数据.但是,我似乎无法在documentation中找到证据.我是否忽略了某些事情,或者这种无操作行为是否可能改变?

最佳答案
实际上,仔细阅读与(here)链接的文档逻辑上意味着.WRITE(NULL,NULL,NULL)应该尝试将列截断为已经存在的长度. I.E.,实际上是一个无操作.

请注意Doc中此提取的斜体部分:

.WRITE (expression,@Offset,@Length):

Specifies that a section of the
value of column_name is to be modified. expression replaces @Length
units starting from @Offset of column_name. …

expression: is the value that is copied to
column_name. … If expression is set to NULL, @Length is
ignored, and the value in column_name is truncated at the specified
@Offset
.

@Offset: is the starting point in the value of column_name at
which expression is written. … If @Offset is NULL, the
update operation appends expression at the end of the existing
column_name value and @Length is ignored
. …

因此,如果@Offset为NULL,则将其视为列的当前长度.

并且,如果expression为NULL,则会在@Offset值处截断该列.

因此,如果两者都为NULL,则以当前长度截断列.我认为这意味着它实际上什么都不做.

转载注明原文:sql-server – 更新VARBINARY(max)列时.WRITE(NULL,NULL,NULL)的语义 - 代码日志