gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 22:25:39 26 4
gpt4 key购买 nike

以下查询的语义是什么

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

如果columnVARBINARY(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) 应该尝试将列截断为它已经达到的长度是。即,实际上是一个空操作。

请注意文档摘录中的斜体部分:

.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,则将其视为列的当前长度。

并且,如果 表达式 为 NULL,则该列将在 @Offset 值处截断。

因此,如果两者都为 NULL,则该列将按其当前长度截断。我认为这意味着它实际上什么也没做。

关于sql-server - 更新 VARBINARY(max) 列时 .WRITE(NULL, NULL, NULL) 的语义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16639574/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com