gpt4 book ai didi

c# - SQL 服务器 : Appending VARBINARY slow performance

转载 作者:太空宇宙 更新时间:2023-11-03 20:05:01 24 4
gpt4 key购买 nike

我使用 64KB 的迭代将文件的字节附加到 VARBINARY 字段到 SQL Server 数据库中。

但是,我相信它会将整个字节对象带回内存,附加字节然后更新导致性能下降的行

我用来更新 VARBINARY 字段的 SQL 语句

long milliseconds = DateTime.Now.Ticks; 

ExecuteSqlCommand("UPDATE dbo.table SET Item = Item + @item WHERE id = @id", new SqlParameter("@item", append), new SqlParameter("@id", id));

long millisecondsAfter = DateTime.Now.Ticks;

long timeTook = millisecondsAfter - milliseconds;

之所以这样说,是因为每次循环后的毫秒数(TimeTook)都比较大。

那么问题来了,是否有更快、更有效的方法来执行上述查询?

---编辑(答案)---

感谢下面的回答,这是新的查询,效果更好

UPDATE dbo.table SET Item.WRITE(@item, NULL, 0) WHERE id = @id", new SqlParameter("@item", append), new SqlParameter("@id", id));

谢谢

最佳答案

这基本上就是人们不阅读文档时发生的情况。

您可以直接通过 SQL 进行部分更新,而无需加载整个对象。

http://msdn.microsoft.com/en-us/library/ms177523%28v=sql.105%29.aspx

是更新语句的语法。请注意“.Write”。

让我引用;

.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. Only columns of varchar(max), nvarchar(max), or varbinary(max) can be specified with this clause. column_name cannot be NULL and cannot be qualified with a table name or table alias.

关于c# - SQL 服务器 : Appending VARBINARY slow performance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24208028/

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