用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - sql代码库

使用 BINARY_CHECKSUM 检测表的行中的更改

2016-08-14 作者: 小章举报

[sql]代码库

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' ]


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...