Table Compare (Data Management)

Summary

Compares two tables or table views and returns the comparison results.

Usage

  • This tool returns messages showing the comparison result. By default, the tool will stop running after encountering the first difference between the inputs. To report all differences, check the Continue Comparison parameter.

  • If the differences reported between the input datasets are due to the addition or deletion of records, only the first reported difference is valid. All reported differences after the addition or deletion will be due to the comparison being out of sequence. The compare tools do not attempt to find the next set of matching records after an added or deleted record is encountered.

  • This tool can report differences and similarities with tabular values and field definitions.

  • Multiple sort fields can be specified. Both the Input Base Table and Input Test Table parameter values are sorted based on the fields you specify. The first field is sorted, the second field is sorted, and so on, in ascending order. Sorting by a common field in both the base and test table ensures that you are comparing the same row from each input dataset.

  • By default, the Compare Type parameter is set to All. This means all properties of the tables being compared will be checked, including field properties and attributes. Specify a different compare type to compare specific properties.

  • The Ignore Options parameter provides the flexibility to omit properties from the comparison. These properties include extension properties, subtypes, and relationship classes.

  • When omitting fields that are not included in the field count comparison, the field definitions and tabular values for those fields are ignored.

  • Attribute tolerances can only be specified for numeric field types.

  • The Output Compare File parameter value will contain all similarities and differences between the Input Base Table and Input Test Table parameter values. This file is a comma-delimited text file that can be viewed and used as a table in ArcGIS. For example, it can be queried to obtain all the object ID values for all the rows that are different.

  • When using this tool in Python, get the status of the comparison from the returned Result object using the index position of 1.(result[1]). The value will be 'true' when no differences are found and 'false' when differences are found.

    Learn more about using tools in Python

Parameters

LabelExplanationData Type
Input Base Table

The data that will be compared with the Input Test Table parameter value. This parameter value is data that you have declared valid. This base data has the correct content and information.

Table View; Raster Layer
Input Test Table

The data that will be compared with the Input Base Table parameter value. This parameter value is data that you have made changes to by editing or compiling new information.

Table View ; Raster Layer
Sort Field

The field or fields that will be used to sort records in the inputs. The records are sorted in ascending order. Sorting by a common field in both inputs ensures that you are comparing the same row from each input dataset.

Value Table
Compare Type
(Optional)

Specifies the comparison type that will be used.

  • AllAll properties will be compared. This is the default.
  • Attributes onlyOnly the attributes and their values will be compared.
  • Schema onlyOnly the schema will be compared.
String
Ignore Options
(Optional)

Specifies the table properties that will not be compared.

  • Ignore extension propertiesExtension properties will not be compared.
  • Ignore subtypesSubtypes will not be compared.
  • Ignore relationship classesRelationship classes will not be compared.
  • Ignore field aliasField aliases will not be compared.
String
Attribute Tolerance
(Optional)

The numeric value that will determine the range in which attribute values are considered equal. This parameter only applies to numeric field types.

Value Table
Omit Fields
(Optional)

The field or fields that will be omitted during comparison. The field definitions and the tabular values for these fields will be ignored.

String
Continue Comparison
(Optional)

Specifies whether the comparison will continue after encountering the first difference between the inputs.

  • Unchecked—The tool will stop after encountering the first difference. This is the default.
  • Checked—The tool will continue after encountering the first difference.

Boolean
Output Compare File
(Optional)

The output file that will contain all similarities and differences between the inputs. This file is a comma-delimited text file that can be viewed and used as a table in ArcGIS.

The output file that will contain all similarities and differences between the inputs. This file is a comma-delimited text file that can be viewed and used as a table in ArcGIS.

File

Derived Output

LabelExplanationData Type
Compare Status

The compare status will be 'true' when no differences are found and 'false' when differences are found.

Boolean

arcpy.management.TableCompare(in_base_table, in_test_table, sort_field, {compare_type}, {ignore_options}, {attribute_tolerances}, {omit_field}, {continue_compare}, {out_compare_file})
NameExplanationData Type
in_base_table

The data that will be compared with the in_test_table parameter value. This parameter value is data that you have declared valid. This base data has the correct content and information.

Table View; Raster Layer
in_test_table

The data that will be compared with the in_base_table parameter value. This parameter value is data that you have made changes to by editing or compiling new information.

Table View ; Raster Layer
sort_field
[sort_field,...]

The field or fields that will be used to sort records in the inputs. The records are sorted in ascending order. Sorting by a common field in both inputs ensures that you are comparing the same row from each input dataset.

Value Table
compare_type
(Optional)

Specifies the comparison type that will be used.

  • ALLAll properties will be compared. This is the default.
  • ATTRIBUTES_ONLYOnly the attributes and their values will be compared.
  • SCHEMA_ONLYOnly the schema will be compared.
String
ignore_options
[ignore_options,...]
(Optional)

Specifies the table properties that will not be compared.

  • IGNORE_EXTENSION_PROPERTIESExtension properties will not be compared.
  • IGNORE_SUBTYPESSubtypes will not be compared.
  • IGNORE_RELATIONSHIPCLASSESRelationship classes will not be compared.
  • IGNORE_FIELDALIASField aliases will not be compared.
String
attribute_tolerances
[[Field, {Tolerance}],...]
(Optional)

The numeric value that will determine the range in which attribute values are considered equal. This parameter only applies to numeric field types.

Value Table
omit_field
[omit_field,...]
(Optional)

The field or fields that will be omitted during comparison. The field definitions and the tabular values for these fields will be ignored.

String
continue_compare
(Optional)

Specifies whether the comparison will continue after encountering the first difference between the inputs.

  • NO_CONTINUE_COMPAREThe tool will stop after encountering the first difference. This is the default.
  • CONTINUE_COMPAREThe tool will continue after encountering the first difference.
Boolean
out_compare_file
(Optional)

The output file that will contain all similarities and differences between the inputs. This file is a comma-delimited text file that can be viewed and used as a table in ArcGIS.

File

Derived Output

NameExplanationData Type
compare_status

The compare status will be 'true' when no differences are found and 'false' when differences are found.

Boolean

Code sample

TableCompare example 1 (Python window)

The following Python window script demonstrates how to use the TableCompare function in immediate mode.

import arcpy
arcpy.management.TableCompare(
    r'c:\Workspace\wells.dbf', r'c:\Workspace\wells_new.dbf', 'WELL_ID', 
    'ALL', 'IGNORE_EXTENSION_PROPERTIES', 'WELL_DEPTH 0.001', '#', 
    'CONTINUE_COMPARE', r'C:\Workspace\well_compare.txt')
TableCompare example 2 (stand-alone script)

The following example demonstrates how to use the TableCompare function in a stand-alone script.

# Name: TableCompare.py
# Description: Compare two dBASE tables and return comparison result.

# Import system modules 
import arcpy

# Set local variables
base_table= "C:/Workspace/wells.dbf"
test_table = "C:/Workspace/wells_new.dbf"
sort_field = "WELL_ID"
compare_type = "ALL"
ignore_option = "IGNORE_EXTENSION_PROPERTIES"
attribute_tolerance = "WELL_DEPTH 0.001"
omit_field = "#"
continue_compare = "CONTINUE_COMPARE"
compare_file = "C:/Workspace/well_compare.txt"

# Process: FeatureCompare
compare_result = arcpy.management.TableCompare(
    base_table, test_table, sort_field, compare_type, ignore_option, 
    attribute_tolerance, omit_field, continue_compare, compare_file)

Environments

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics