USE AdventureWorks2012; |
GO |
CREATE TABLE myTable (column1 int , column2 varchar (256)); |
GO |
INSERT INTO myTable VALUES (1, 'test' ); |
GO |
SELECT BINARY_CHECKSUM(*) from myTable; |
GO |
UPDATE myTable set column2 = 'TEST' ; |
GO |
SELECT BINARY_CHECKSUM(*) from myTable; |
GO |
使用方法如下: |
select id,binary_checksum(*) from tb1 |
select id binary_checksum(*) from tb2 |
你比较两个表的校验值即可,若校验值相同,则表示通过。 |
|
-------------------------------------------- |
详细如下: |
select A.id from |
( select id,CA=binary_checksum(*) from tb1) A where A.CA not in ( select B.CB from |
( select id,CB=binary_checksum(*) from tb2) B |
|
--------------- |
|
发表于 2006-7-2 19:33 |只看该作者 当然,若你单纯想快速的检验表与表之间是否相同,就直接用sp_table_validation吧。 |
实际上它的核心也是使用了binary_checksum |
----------------- |
Either returns rowcount or checksum information on a table or indexed view , or compares the provided rowcount or checksum information with the specified table or indexed view . This stored procedure is executed at the Publisher on the publication database and at the Subscriber on the subscription database . Not supported for Oracle Publishers. |
|
Syntax |
|
sp_table_validation [ @ table = ] 'table' |
[ , [ @expected_rowcount = ] type_of_check_requested OUTPUT ] |
[ , [ @expected_checksum = ] expected_checksum OUTPUT ] |
[ , [ @rowcount_only = ] rowcount_only ] |
[ , [ @owner = ] 'owner' ] |
[ , [ @full_or_fast = ] full_or_fast ] |
[ , [ @shutdown_agent = ] shutdown_agent ] |
[ , [ @table_name = ] table_name ] |
[ , [ @column_list = ] 'column_list' ] |
by: 发表于:2017-09-22 09:42:34 顶(0) | 踩(0) 回复
??
回复评论