开发者

How to Prevent Checksum() from generating Duplicate Values in sql server

As it is 开发者_开发百科known there is a probable chance of checksum generating duplicate values, and I am supposed to find an approach which prevents checksum from generating duplicate Values... Please help

Thanks n Regards


You can't. CHECKSUM can never be guaranteed unique.

MSDN for CHECKSUM says to use HASHBYTES instead which has far less chance of duplications.

However, any hashing function can not guarantee 100% that you will have no duplicates. if you want "no duplicates" then you shouldn't hash...


Consider using HashBytes

From MSDN:

When an MD5 hash algorithm is specified, the probability of HashBytes returning the same result for two different inputs is much lower than that of CHECKSUM.

Example:

DECLARE @HashThis nvarchar(4000);
SELECT @HashThis = CONVERT(nvarchar(4000),'dslfdkjLK85kldhnv$n000#knf');
SELECT HashBytes('SHA1', @HashThis);
GO
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜