为 sql server 中的一组行生成哈希 [英] Generate a hash for a set of rows in sql server

查看:37
本文介绍了为 sql server 中的一组行生成哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL Server 2012 有没有办法生成一组行和列的散列?

Is there any way in SQL Server 2012 to generate a hash of a set of rows and columns?

我想生成一个散列,将它存储在父记录中.当更新进来时,我会将传入的哈希与父记录哈希进行比较,我将知道数据是否已更改.

I want to generate a hash, store it on the parent record. The when an update comes in, I'll compare the incoming hash with the parent record hash and I'll know whether the data has changed.

所以这样的事情会很好:

So something like this would be nice:

SELECT GENERATEHASH(CONCATENATE(Name, Description, AnotherColumn))
FROM MyChildTable WHERE ParentId = 2 -- subset of data belong to parent record 2

"CONCATENATE" 将是一个聚合函数,它不仅可以连接列,还可以连接结果集中的行.与 MAX 类似,但以字符串连接形式返回所有内容.

"CONCATENATE" would be an aggregate function which would not only concat the columns, but also, the rows inside the resultset. Like MAX, but returning everything as a string concatenation.

希望这能帮助你理解我的意思!

Hopefully this helps you see what I mean anyway!

我试图解决的根本问题是我客户的系统执行了大量分层数据的导入.如果我可以通过使用哈希来避免处理,那么我认为这会节省很多时间.目前,当必须处理重复数据时,SP 的运行速度要慢 300%.

The fundamental problem I'm trying to solve is that my client's system perform imports of vast amounts of hierarchical data. If I can avoid processing through the use of hashes, then I would think this will save a lot of time. At the moment, the SP is running 300% slower when having to process duplicate data.

非常感谢

推荐答案

您可以使用 CHECKSUM_AGG 聚合.它就是为此目的而制作的.

You can use the CHECKSUM_AGG aggregate. it is made for that purpose.

这篇关于为 sql server 中的一组行生成哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆