CHECK_SUM returns same value for diff. inputs

  • I was performing some case sensitive comparsions and as one of options was to use check sum, anyway I conluded that CHECK_SUM and BINARY_CHECK sum functions return same value for different inputs.As far as I know those functions are like hash functions and CHECKSUM applied over any two lists of expressions returns the same value if the corresponding elements of the two lists have the same type and are equal when compared using the equals operator.

    SELECT    BINARY_CHECKSUM('A') AS [Checksum value for 'A'],

        BINARY_CHECKSUM('AAAAAAAAAAAAAAAAA') AS [Checksum value for 'AAAAAAAAAAAAAAAAA']

    SELECT    CHECKSUM('AB') AS [Checksum value for 'A'],

        CHECKSUM('ABABABABABABABABABABABABABABABABAB') AS [Checksum value for 'ABABABABABABABABABABABABABABABABAB']

    It seems that if put 17 times first expression as second expression result will be same.Do I misunderstand those functions or this is a BUG?

  • I am getting the same return on your second select: "AB" versus 17 x's "AB". 

    I do not use these functions much, but BOL indicate that case sensitivity is of issue. 

    SELECT    BINARY_CHECKSUM('A') AS [Checksum value for 'A'],

        BINARY_CHECKSUM('Aa') AS [Binary_Checksum value for 'a']

    SELECT    CHECKSUM('AB') AS [Checksum value for 'A'],

        BINARY_CHECKSUM('ABABABABABABABABABABABABABABABABAB') AS [Binary_Checksum value for 'ABABABABABABABABABABABABABABABABAB']

    SELECT    CHECKSUM('AB') AS [Checksum value for 'A'],

        CHECKSUM('ABABABABABABABABABABABABABABABABAB') AS [Checksum value for 'ABABABABABABABABABABABABABABABABAB']

    I wasn't born stupid - I had to study.

  • The only guarantee you have with these functions is that BINARY_CHECKSUM will always return the same value for 2 identical values, and CHECKSUM will always return the same value for 2 values which are the same except for case.

    Any 2 given values may give the same result but not be the same value (as in your examples).

    I don't think you've discovered anything which contradicts this guarantee, so I don't think you've found a bug!

    Check sum, therefore, doesn't look like the right tool for the job you're doing...

     

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply