Table Compare (Data Management)
Summary
Compares two tables or table views and returns the comparison results. This tool can report differences and similarities with tabular values and field definitions.
Usage
-
This tool returns messages showing the comparison result. By default, it will stop executing after encountering the first miscompare. To report all differences, check on the Continue Comparison parameter.
-
Multiple sort fields may be specified. Both the Input Base Table and Input Test Table are sorted based on the fields you specify. The first field is sorted, then the second field, 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 is set to ALL. This means all properties of the tables being compared will be checked, including such things as field properties and attributes. However, you may choose a different compare type to check only specific properties of the tables being compared.
-
The Ignore Options provide 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, and 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 will contain all similarities and differences between the Input Base Table and the Input Test Table. This file is a comma-delimited text file which can be viewed and used as a table in ArcGIS. For example, this table can be queried to obtain all the ObjectID values for all the rows that are different.
-
When using this tool in Python, you can get the status of this tool using result.getOutput(1). The value will be 'true' when no differences are found and 'false' when differences are detected.
Syntax
Parameter | Explanation | Data Type |
in_base_table |
The Input Base Table is compared with the Input Test Table. The Input Base Table refers to tabular data that you have declared valid. This base data has the correct field definitions and attribute values. | Table View; Raster Layer |
in_test_table |
The Input Test Table is compared against the Input Base Table. The Input Test Table refers to data that you have made changes to by editing or compiling new fields, new records, or new attribute values. | Table View ; Raster Layer |
sort_field [sort_field,...] |
The field or fields used to sort records in the Input Base Table and the Input Test Table. The records are sorted in ascending order. Sorting by a common field in both the Input Base Table and the Input Test Table ensures that you are comparing the same row from each input dataset. | Value Table |
compare_type (Optional) |
The comparison type. ALL is the default. The default will compare all properties of the tables being compared.
| String |
ignore_options (Optional) |
These properties will not be compared during comparison.
| String |
attribute_tolerances [[Field, {Tolerance}],...] (Optional) |
The numeric value that determines the range in which attribute values are considered equal. This 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) |
Indicates whether to compare all properties after encountering the first mismatch.
| Boolean |
out_compare_file (Optional) |
This file will contain all similarities and differences between the Input Base Table and the Input Test Table. This file is a comma-delimited text file which can be viewed and used as a table in ArcGIS. | File |
Code Sample
The following Python window script demonstrates how to use the TableCompare function in immediate mode.
import arcpy
from arcpy import env
arcpy.TableCompare_management(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' )
Example of how to use the TableCompare tool in a stand-alone script.
# Name: TableCompare.py
# Description: Compare two dBASE tables and return comparison result.
# Author: ESRI
# import system modules
import arcpy
try:
# 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.TableCompare_management(base_table, test_table, sort_field, compare_type, ignore_option, attribute_tolerance, omit_field, continue_compare, compare_file)
print compare_result
print arcpy.GetMessages()
except:
# Print error message if an error occurs
print arcpy.GetMessages()