MSSQL 2005, 2008自带 表比较工具 tablediff.exe

来源:互联网 发布:无主之地mac 迅雷下载 编辑:程序博客网 时间:2024/05/17 11:56

SQL Server 2005新增工具工具TABLEDIFF,用于比价两张表之间的差异。可以比较行数、架构、列;可将比较结果输出成T-SQL脚本或者输出到文件或者表中。

假定的SQL SERVER默认安装在c盘,那么这个工具位于“C:/Program Files/Microsoft SQL Server/90/COM/tablediff.exe”

C:/Program Files/Microsoft SQL Server/90/COM>tablediff.exe /?
Microsoft (R) SQL Server Replication Diff Tool
Copyright (C) 1988-2005 Microsoft Corporation. All rights reserved.

User-specified agent parameter values:
/?

Replication Diff Tool Command Line Options

usage: tablediff

-- Source Options -- 源
-sourceserver Source Host 源数据库服务器,如果服务器上安装两个实例,还得使用“服务器名称”/实例名称
-sourcedatabase Source Database 服务器上的数据库名称
-sourceschema Source Schema Name 表或者视图的所有者,一般就是dbo
-sourcetable Source Table or View 表或者视图名称

-sourceuser Source Login login名称

-sourcepassword Source Password 密码
-sourcelocked Lock the source table/view durring tablediff 比较的时候是否lock表和视图

-- Destination Options --
-destinationserver Destination Host
-destinationdatabase Destination Database
-destinationschema Destination Schema Name
-destinationtable Destination Table or View
-destinationuser Destination Login
-destinationpassword Destination Password
-destinationlocked Lock the destination table/view durring tablediff

-- Misc Options --
-t Timeout
-c Column Level Diff 比较列的差异
-f Generate Fix SQL (You may also specify a file name and path) 将两者之间的不同生成sql 脚本
-q Quick Row Count 只比较行数和架构
-et Specify a table to put the errors into 创建结果表
-dt Drop the error table if it exists 如果有结果表 这个选项可以删除
-o Output file 输出文件的路径
-b Number of bytes to read for blob data types (Default 8000)
-strict Strict compare of source and destination schema
-rc Number of retries retry的次数
-ri Retry interval 重试的等待时间


例子:

数据库服务器.上有数据库360,dbA上有表answer,使用下面的查询建立两个新表:

select *  into answer2 from dbo.answer where id <9000
select *  into answer3 from dbo.answer where id <19000

这样我们得到了新表answer2和answer3,下面来演示比较这两个表:
tablediff.exe -sourceserver log-szzb -sourcedatabase 360 -sourcetable answer2 -destinationserver log-szzb -destinationdatabase 360 -destinationtable answer3 -et DiffsTable

刷新后在数据库360中得到一个新表“DiffsTable”,这个就是比较的结果。

原创粉丝点击