SQLServer2005引入了TableDiff工具用来对比两个表之间的结构以及数据差异,在使用中可能遇到一些错误如下:
错误1.
原因:对比的源表没有主键的错误(在不使用-strict参数的情况下,目的表可以没有主键):
错误描述:The replication table difference tool requires the comparison tables/views to have either a primary key, identity, rowguid or unique key column.
错误2.
原因:对比的表的列数据类型不一致(如源表是varchar,目的表是int,但数据可以转换)
错误描述:如果不加-strict参数,下面的类型可以隐式转换,如果加了-strict参数,类型必须一致,否则错误一样
==============================================
源数据类型 目标数据类型
---------------------------------------------- -
tinyint smallint、int 或者 bigint
----------------------------------------------
smallint int 或者 bigint
----------------------------------------------
int bigint
----------------------------------------------
timestamp varbinary
----------------------------------------------
varchar(max) text
----------------------------------------------
nvarchar(max) ntext
----------------------------------------------
varbinary(max) image
----------------------------------------------
text varchar(max)
----------------------------------------------
ntext nvarchar(max)
----------------------------------------------
image varbinary(max)
==============================================
Table {dbname}.dbo.{tablename} on {sourceserver} and Table {dbname}.dbo.{tablename} on {destserver} have different schemas and cannot be compared.
错误3.
原因:对比的表包含sql_variant数据类型的列(不支持)
错误描述:Cannot compare the tables because they contain one or more columns of data type sql_variant. The tablediff utility does not support columns of this type.
以上只是其中一些问题,除了这些问题,还需要注意:
tablediff 实用工具不能用于非 SQL Server 服务器。
另外在权限方面需要注意的是:
若要比较表,您必须有要比较的表对象的 SELECT ALL 权限。
若要使用 -et 选项,您必须是 db_owner 固定数据库角色的成员,或者在订阅数据库中至少有 CREATE TABLE 权限,并且对 目标服务器上的目标所有者架构拥有 ALTER 权限。
若要使用 -dt 选项,您必须是 db_owner 固定数据库角色的成员,或者至少对目标服务器上的目标所有者架构拥有 ALTER 权限。
若要使用 -o 选项,您必须对指定的文件目录位置拥有写入权限。