Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Sql Server Programming

BINARY_CHECKSUM uniqueness


hi,

is it safe to assume that BINARY_CHECKSUM will return the same result ONLY
if the parameters passed to it are the same?

i.e. if i have a table Contact with the following columns ( Firstname
varchar(50), lastname varchar(50), email varchar(80) )
Should i assume that BINARY_CHECKSUM( Firstname, lastname, email) returns
different values as long as the data in those three columns are different
and that it would return the same value ONLY is the data in the fields is
EXACTLY the same?

No.  Different values can return the same value in BINARY_CHECKSUM.

Tom

"Joey" <j@mail.com> wrote in message

news:OLDI%23nFqHHA.3660@TK2MSFTNGP04.phx.gbl...

SELECT BINARY_CHECKSUM('Z'),
 BINARY_CHECKSUM('ZZZZZZZZZZZZZZZZZ')

If you want better odds of a unique hash, consider using a collision-free
hash function like SHA.

"Joey" <j@mail.com> wrote in message

news:OLDI%23nFqHHA.3660@TK2MSFTNGP04.phx.gbl...

On 6 Jun, 17:40, "Joey" <j@mail.com> wrote:

> hi,

> is it safe to assume that BINARY_CHECKSUM will return the same result ONLY
> if the parameters passed to it are the same?

> i.e. if i have a table Contact with the following columns ( Firstname
> varchar(50), lastname varchar(50), email varchar(80) )
> Should i assume that BINARY_CHECKSUM( Firstname, lastname, email) returns
> different values as long as the data in those three columns are different
> and that it would return the same value ONLY is the data in the fields is
> EXACTLY the same?

No. CHECKSUM returns an INT, for which there are only about 4 billion
possible values. You don't have to generate many checksums before you
hit a duplicate. Do the math.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc