July 23, 2006 at 9:46 pm
My tables have UniqueIdentifier PKs. To help with performance, there is also an int computed column which is set by default to CHECKSUM([PKCol]). These 2 cols form the clustered index.
I would like to search on both the PK and the computed col.
However, .Net GetHashCode() on the UniqueIdentifier does not equal the sql CHECKSUM of the same UniqueIdentifier.
Is there a way in .Net I can get the same int that sql CHECKSUM produces?
What algorithm does sql use for CHECKSUM?
July 26, 2006 at 8:00 am
This was removed by the editor as SPAM
August 14, 2006 at 9:11 am
The CHECKSUM function uses one of the many existing hashing algoriths. According to this site it uses MD5 for SQL7/2000. I guess SQL2K5 uses the same algorith.
You might want to use another algorith in SQL (by using the HASBYTES function). There are several algoriths that you can choose of: MD2, MD4, MD5, SHA, or SHA1. See MSDN for more info on HASHBYTES.
This site decribes .Net's method GetHashCode() as follows: "The GetHashCode virtual method of Object is an example of a simple hash function not intended for cryptographic purposes.". I wasn't able to figure out what hashing method GetHashCode uses, but I would suggest you use an MD5 hashing method in your code. That would solve your problem. MSDN has some code examples.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply