Remove Join (Data Management)
Summary
Removes a join from a feature layer or table view.
Usage
-
The Join parameter is the name of the table that was joined to the input layer or table view.
- If the join table was a dBASE file named MyTable.dbf, the join name would be "MyTable"; so to remove it, specify "MyTable".
- If the join table was an INFO or Geodatabase Table named MyTable2, the Join Name would be "MyTable2"; so to remove it, specify "MyTable2".
- The join name will not reflect the name of the table view itself, but rather the source of the table view. Therefore, if a table view is named TableView1 and points at mytable.dbf, the name of the join will be "mytable".
-
When a layer is joined to two tables and the first join is removed, then both joins will be removed. For example, Layer1 is joined to TableA. Then Layer1 is joined to TableB. If the join to TableA is removed, the join to TableB is also removed.
-
This tool is not limited to working within ArcMap; it works on layers and table views in other ArcGIS applications and in scripts. The Make Feature Layer tool makes a layer from a feature class, and the Make Table View tool creates a table view from an input table or feature class. The layer or table view can then be used as the input to the Add Join and Remove Join tools.
Syntax
Parameter | Explanation | Data Type |
in_layer_or_view |
The layer or table view from which the join will be removed. | Mosaic Layer; Raster Catalog Layer; Raster Layer; Table View |
join_name (Optional) |
The join to be removed. | String |
Code Sample
The following Python window script demonstrates how to use the RemoveJoin tool in immediate mode in ArcMap on a feature layer in the TOC named veglayer.
arcpy.RemoveJoin_management("veglayer", "vegtable")
This stand-alone script shows the RemoveJoin function as part of a workflow to add a field to a table and calculate its values based on the values in a field from a joined table.
# AddFieldFromJoin.py
# Description: Adds a field to a table, and calculates its values based
# on the values in a field from a joined table
# Import system modules
import arcpy
from arcpy import env
try:
# set the environments
env.workspace = "C:/data"
env.qualifiedFieldNames = "UNQUALIFIED"
# Define script parameters
inFeatures = "Habitat_Analysis.gdb/vegtype"
layerName = "veg_layer"
newField = "description"
joinTable = "vegtable.dbf"
joinField = "HOLLAND95"
calcExpression = "!vegtable.VEG_TYPE!"
outFeature = "Habitat_Analysis.gdb/vegjoin335"
# Add the new field
arcpy.AddField_management (inFeatures, newField, "TEXT")
# Create a feature layer from the vegtype featureclass
arcpy.MakeFeatureLayer_management (inFeatures, layerName)
# Join the feature layer to a table
arcpy.AddJoin_management (layerName, joinField, joinTable, joinField)
# Populate the newly created field with values from the joined table
arcpy.CalculateField_management (layerName, newField, calcExpression, "PYTHON")
# Remove the join
arcpy.RemoveJoin_management (layerName, "vegtable")
# Copy the layer to a new permanent feature class
arcpy.CopyFeatures_management (layerName, outFeature)
except Exception, e:
import traceback, sys
tb = sys.exc_info()[2]
print "Line %i" % tb.tb_lineno
print e.message