Add Relate (Data Management)

Summary

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

The records in the Relate Table parameter value are matched to the records in the input Layer Name or Table View parameter value. 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 or table.

Usage

  • If the input is a feature class or dataset path, this tool will 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 Object ID field. The relate table is not required to contain an Object ID 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 the relate table on which the relate will be based can improve performance. This can be done with the Add Attribute Index tool.

  • When the input layer has a relationship and the Automatically select related data property is checked, a selection on the input layer will also select records in the related table.

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)

Specifies the cardinality of the relationship.

  • One to oneThe relationship between the input table and related table will be one to one. For example, one record in the input table will have only one matching record in the related table.
  • One to manyThe relationship between the input table and related table will be 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 manyThe relationship between the input table and related table will be 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)

Specifies the cardinality of the relationship.

  • ONE_TO_ONEThe relationship between the input table and related table will be one to one. For example, one record in the input table will have only one matching record in the related table.
  • ONE_TO_MANYThe relationship between the input table and related table will be 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_MANYThe relationship between the input table and related table will be 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
arcpy.management.AddRelate("Parcel", "ParcelID", "owner_table", "ParcelID", 
                           "Owner2Parcel")

Environments

Related topics