Add Relate (Data Management)

Summary

Relates a layer to another layer or table based on a field value. Feature layers, table views, and raster layers with a raster attribute table are supported.

The records in the Relate Table are matched to the records in the input Layer Name or Table View. A match is made when the input relate field and output relate field are equal. Relates do not modify data; they are a property of the layer.

Usage

  • If the input is a feature class or dataset path, this tool will automatically create and return a new layer with the result of the tool applied.

  • Records from the Relate Table can be matched to more than one record in the input layer or table view.

  • The Relate Table can be a geodatabase table or a dBASE file. The Relate Table does not have to be a layer.

  • The input must have an ObjectID field. The Relate Table is not required to contain an ObjectID field.

  • To save the relate for use in another project, save the layer to a layer file using the Save Layer To File tool. This only applies to layers; table views cannot be saved in this manner.

  • To make a permanent relate, use the Create Relationship Class tool.

  • Indexing the fields in the input layer or table view and Relate Table on which the relate will be based can improve performance. This can be done with the Add Attribute Index tool.

Parameters

LabelExplanationData Type
Layer Name or Table View

The layer or table view to which the relate table will be related.

Mosaic Layer; Raster Layer; Table View
Input Relate Field

The field in the input layer or table view on which the relate will be based.

Field
Relate Table

The table or table view to be related to the input layer or table view.

Mosaic Layer; Raster Layer; Table View
Output Relate Field

The field in the relate table that contains the values on which the relate will be based.

Field
Relate Name

The unique name given to a relate.

String
Cardinality
(Optional)

The cardinality of the relationship.

  • One to oneSpecifies that the relationship between the input table and related table is one to one. For example, one record in the input table will only have one matching record in the related table.
  • One to manySpecifies that the relationship between the input table and related table is one to many. For example, one record in the input table can have multiple matching records in the related table. This is the default.
  • Many to manySpecifies that the relationship between the input table and related table is many to many. For example, many records with the same value in the input table can have multiple matching records in the related table.
String

Derived Output

LabelExplanationData Type
Updated Input Layer or Table View

The updated input dataset.

Table View; Raster Layer; Mosaic Layer

arcpy.management.AddRelate(in_layer_or_view, in_field, relate_table, relate_field, relate_name, {cardinality})
NameExplanationData Type
in_layer_or_view

The layer or table view to which the relate table will be related.

Mosaic Layer; Raster Layer; Table View
in_field

The field in the input layer or table view on which the relate will be based.

Field
relate_table

The table or table view to be related to the input layer or table view.

Mosaic Layer; Raster Layer; Table View
relate_field

The field in the relate table that contains the values on which the relate will be based.

Field
relate_name

The unique name given to a relate.

String
cardinality
(Optional)

The cardinality of the relationship.

  • ONE_TO_ONESpecifies that the relationship between the input table and related table is one to one. For example, one record in the input table will only have one matching record in the related table.
  • ONE_TO_MANYSpecifies that the relationship between the input table and related table is one to many. For example, one record in the input table can have multiple matching records in the related table. This is the default.
  • MANY_TO_MANYSpecifies that the relationship between the input table and related table is many to many. For example, many records with the same value in the input table can have multiple matching records in the related table.
String

Derived Output

NameExplanationData Type
out_layer_or_view

The updated input dataset.

Table View; Raster Layer; Mosaic Layer

Code sample

AddRelate example 1 (Python window)

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

import arcpy
relate = arcpy.AddRelate_management("Parcel", "ParcelID", "owner_table", 
                                    "ParcelID", "Owner2Parcel")

Environments