Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

CHECKSUM Expand / Collapse
Author
Message
Posted Sunday, September 6, 2009 3:47 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, July 19, 2012 9:22 AM
Points: 52, Visits: 381
When I execute below SQL statement in SQL server 2000, I get the same value of 128414903 for the CHECKSUM in two different rows with different data. Why is that?

DECLARE @checksum TABLE
(
CustomerNo CHAR(17)
,Address CHAR(40)
)

INSERT INTO @checksum
SELECT '00000000014331462','A15 Block No.: 3' UNION ALL
SELECT '00000000061051462','F23 Block No.: 5'

SELECT CHECKSUM(CustomerNo,Address)
FROM @checksum



- Zahran -
Post #783416
Posted Sunday, September 6, 2009 12:23 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, October 3, 2010 3:50 AM
Points: 146, Visits: 178
which version of SQL Server 2000 you are running ? SP4? later ?
Post #783509
Posted Sunday, September 6, 2009 10:03 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Monday, November 3, 2014 4:30 PM
Points: 4,574, Visits: 8,366
Please open BOL on CHECKSUM and read 2nd paragraph of "Remarks".
Post #783594
Posted Monday, September 7, 2009 12:45 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, July 19, 2012 9:22 AM
Points: 52, Visits: 381
which version of SQL Server 2000 you are running ? SP4? later ?


It's RTM version.


- Zahran -
Post #783633
Posted Monday, September 7, 2009 12:48 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, July 19, 2012 9:22 AM
Points: 52, Visits: 381
which version of SQL Server 2000 you are running ? SP4? later ?


It's RTM version.


- Zahran -
Post #783634
Posted Monday, September 7, 2009 12:51 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, July 19, 2012 9:22 AM
Points: 52, Visits: 381
which version of SQL Server 2000 you are running ? SP4? later ?


It's RTM version.


- Zahran -
Post #783636
Posted Monday, September 7, 2009 10:51 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, October 3, 2010 3:50 AM
Points: 146, Visits: 178
Sergiy - the paragrah you mentioned change nothing. hash is a hash - and for a given string should always return the same value. did you try to run his query on your sql ?
Post #783860
Posted Monday, September 7, 2009 3:19 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Monday, November 3, 2014 4:30 PM
Points: 4,574, Visits: 8,366
Marcin Gol [SQL Server MVP] (9/7/2009)
Sergiy - the paragrah you mentioned change nothing. hash is a hash - and for a given string should always return the same value. did you try to run his query on your sql ?

You probably did not reach the last sentence of the paragraph.
Post #783916
Posted Monday, September 7, 2009 3:37 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Sunday, November 4, 2012 12:23 PM
Points: 1,893, Visits: 3,932
Hi Zahran

Little quote from BOL
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.

Keep in mind. A hash is as unique as possible, but it's not a guarantee for real uniqueness. If you have a VARCHAR(100) column it represents much more possible values than an INT.

You can use HASHBYTES or BINARY_CHECKSUM to get a better hash than old CHECKSUM function.
SELECT 
HASHBYTES('MD5', CustomerNo + Address)
,BINARY_CHECKSUM(CustomerNo, Address)
,CHECKSUM(CustomerNo, Address)
FROM @checksum

Anyway, a hash will never be a 100% guarantee for uniqueness. If you need unique values use an IDENTITY column or a GUID.

Greets
Flo

Edit: Dang! Sorry, didn't notice this is the 2000 forum. Probably the new functions are not available...



The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
Post #783919
Posted Monday, September 7, 2009 4:09 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, October 3, 2010 3:50 AM
Points: 146, Visits: 178
Sergiy (9/7/2009)
Marcin Gol [SQL Server MVP] (9/7/2009)
Sergiy - the paragraph you mentioned change nothing. hash is a hash - and for a given string should always return the same value. did you try to run his query on your sql ?

You probably did not reach the last sentence of the paragraph.


i read it but i feel that we don't understand each other

my version: for a given string we should always receive same hash, did i say that hash is unique? nope.

maybe other question is right here ... does the implemantion of checksum function has changed over the time ? (sql 2000 -> 2008?); if don't why im getting other values of checksum than Zahran ?
Post #783933
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse