SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Using the CheckSum Function - SQL School Video


Using the CheckSum Function - SQL School Video

Author
Message
Brian Knight
Brian Knight
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: Moderators
Points: 4131 Visits: 235
Comments posted to this topic are about the item Using the CheckSum Function - SQL School Video

Brian Knight
Free SQL Server Training Webinars
sqlagent007
sqlagent007
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 Visits: 250
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.
Brian Knight
Brian Knight
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: Moderators
Points: 4131 Visits: 235
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
Anipaul
Anipaul
SSCrazy Eights
SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)

Group: General Forum Members
Points: 8665 Visits: 1407
Nice one...



patrickpk
patrickpk
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 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!
emmanuel.vanneste
emmanuel.vanneste
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 6
you should idd use MD5!


using checksum results easily in duplicates , eg
select checksum('eeeeeeeeeeeeeeee')
select checksum('dddddddddddddddd')
jezman
jezman
SSC Journeyman
SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)

Group: General Forum Members
Points: 89 Visits: 129
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!
anand.ramanan
anand.ramanan
SSC-Enthusiastic
SSC-Enthusiastic (109 reputation)SSC-Enthusiastic (109 reputation)SSC-Enthusiastic (109 reputation)SSC-Enthusiastic (109 reputation)SSC-Enthusiastic (109 reputation)SSC-Enthusiastic (109 reputation)SSC-Enthusiastic (109 reputation)SSC-Enthusiastic (109 reputation)

Group: General Forum Members
Points: 109 Visits: 70
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.
Misha_SQL
Misha_SQL
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1364 Visits: 1010
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!



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search