Select to view content in your preferred language

Remove all joins programatically

02-13-2012 02:37 PM
Status: Implemented
Labels (1)
New Contributor II


would be nice to have the option of removing ALL joins from a table or feature class programatically just like you can from the GUI instead of having to remove them individually.

Instead of passing in the name of the join as a string, use a '*' or '#' to represent all.


Here's a little function that does this. You could use this in an arcpy.mapping script or with the Calculate Value tool in Model Builder. Another approach I've used to drop joins in scripting is to delete the layer or table view and recreate it. (This approach may not work well in Model Builder or a script that operates on an existing layer as it would delete the layer from the map!)

def RemoveAllJoins(tbl):
    """Remove all joins from a layer or table view"""
    flds = [ for f in arcpy.ListFields(tbl)]
    wk = os.path.dirname(arcpy.Describe(tbl).catalogPath)
    joins = [arcpy.ParseFieldName(f, wk).split(", ")[-2] for f in flds]
    joins = list(set(joins)) # unique the list
    if joins[0] == "(null)":
        print("no join active")
        # remove base table name from list and remove all joins
        for j in joins:
            arcpy.RemoveJoin_management(tbl, j)
            print("Removed join {}".format(j))

For anyone referring back to this page, calling without the optional join_name parameter will remove all joins from the feature layer or table view.

RemoveJoin will throw ERROR 000229 if no join is present, so be sure to catch arcpy.ExecuteError if you want to handle the exception.

Status changed to: In Product Plan

As stated above, running Remove Join with no join name specified will result in removing all joins, in ArcGIS Pro 3.0.

Status changed to: Implemented

See Ideas in ArcGIS Pro 3.0 for all of the other ideas you can look forward to when you upgrade.

Also be sure to check out the What's New documentation: