Welcome to weblogs.com.pk Sign in | Join | Help

Tsql :: Checksum

Comparing Checksum is one of the straight forward techniques to know if two things are different or not, especially when you are comparing some vector quantities. SQL Server 2005’s TSQL has two new relevant functions in this regard, checksum() and checksum_agg()

Consider a test table having some values. Using checksum() you can have a computed checksum.

create table Test (
  
username nvarchar(50),
  
password nvarchar(50)
)
go
insert into test values (null, null);
insert into test values ('fareed', null);
insert into test values ('khurram', null);
insert into test values ('fareed', '1234');
insert into test values ('khurram', '5678');
insert into test values ('khurram', '1234');

select username, password, checksum(username, password)
from test

One can even add a calculated column using the following

alter table test add cSum as checksum(username, password);

And when you need to compare two tables; simply use checksum_agg

select * into test2
from test;
delete from test2 where password is null;
go
select
  
(select checksum_agg(csum) from test),
  
(select checksum_agg(csum) from test2);

Published Tuesday, May 16, 2006 6:12 PM by khurram
Filed under: ,

Comments

No Comments

New Comments to this post are disabled