|
|
|
SSCommitted
      
Group: Moderators
Last Login: Monday, August 13, 2012 1:06 PM
Points: 1,928,
Visits: 224
|
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 4:48 PM
Points: 38,
Visits: 167
|
|
this is a good/ dangerous technique. I have implemented this is a production system and got burned by duplicate checksum values on different columns (hash collision). Them more data you can put into the check sum the less likely you will have duplicates. maybe.
But good demo.
|
|
|
|
|
SSCommitted
      
Group: Moderators
Last Login: Monday, August 13, 2012 1:06 PM
Points: 1,928,
Visits: 224
|
|
That's true. There's a slight chance of duplicate checksums. Another technique that I've used is HASHBYTES similar to this:
select HASHBYTES('md5',NAME + isnull(Color,'Unkown')), * FROM Production.Product
It takes longer to run but it produces very unique values like 0x313FB214C93591081E720123253B1398.
Brian Knight Free SQL Server Training Webinars
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Thursday, May 16, 2013 2:50 AM
Points: 4,785,
Visits: 1,334
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, May 05, 2011 11:42 AM
Points: 3,
Visits: 117
|
|
Brian, That's an excellent tip! Wee're in the middle of a conversion project for HR & FIN and this will absolutely help. Great Job!
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, October 19, 2010 8:44 AM
Points: 1,
Visits: 6
|
|
you should idd use MD5!
using checksum results easily in duplicates , eg select checksum('eeeeeeeeeeeeeeee') select checksum('dddddddddddddddd')
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 8:56 AM
Points: 23,
Visits: 104
|
|
Agreed, having worked on a system where someone decided to implement checksums to manage change control I know from bitter experience that it will bite you at some point. I think we found numbers that were related in some mathematical way (I forget exactly) would give the same value. But we also had examples of company name strings that gave the same value.
If getting the integrity perfect is important I'd suggest not using this idea. For something that is supposed to be a rare occurrence it happened surprisingly frequently!
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Tuesday, March 12, 2013 3:40 PM
Points: 39,
Visits: 64
|
|
When implementing the HashBytes or CheckSum is it optimal to do these checks manually in the respective update stored procedure, or is it better to be used trigger based? What is the best practice?
My goal is to provide auditing (stored in a separate audit table) in sql server 2005 when a specific piece of data e.g. username or users password is modified, when the enter user row is updated.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 5:54 PM
Points: 525,
Visits: 617
|
|
First of all kudos to Brian for his videos. I absolutely love them and have learned so much. Secondly I agree with the others regarding the dangers of using CHECKSUM against string values due to the non-uniqueness of the result. I think it's fairly safe to use across several numeric/date columns though. I have never used HASHBYTES before, so this is a great tip as well.
Thank you!
|
|
|
|