Delete all attribute indexes in a file geodatabase

06-29-2018 11:59 AM
Occasional Contributor II

I have about 30 feature classes in an FGDB. I am looking for a script to remove all attribute indexes, as I will need to do this for multiple FGDBs eventually. 

My file path is:


I started with this article

Remove all attribute indexes using arcpy 

But got stuck at line 02

  1. dsc = arcpy.Describe("sap")  
0 Kudos
2 Replies
MVP Regular Contributor

As a reference, here is the script from the link mentioned:

arcpy.env.workspace = "e:/crs/mobile/mobile.gdb"  
dsc = arcpy.Describe("sap")  
lstIndex = [ for i in dsc.Indexes][1:]  
print lstIndex"sap",lstIndex)  

Line 2 is asking for a description of a feature class named "sap" inside the geodatabase.  The script then puts the index names in a list starting with the second item.  I assume this removes the FDO_OBJECTID from the list, but it keeps other items like FDO_SHAPE which you probably would not want to delete.

0 Kudos
MVP Esteemed Contributor

If you want to remove all attribute indexes from all feature classes in a geodatabase, the following will get the job done:

import arcpy
import os

gdb = # path to geodatabase

walk = arcpy.da.Walk(gdb, datatype="FeatureClass")
for root, _, fcs in walk:
    for fc in fcs:
        fc = os.path.join(root, fc)
        desc = arcpy.Describe(fc)
        OIDFieldName = desc.OIDFieldName
        shapeFieldName = desc.shapeFieldName
        idxs = [
   for i in desc.indexes
            if not any( in (OIDFieldName, shapeFieldName) for f in i.fields)
        arcpy.RemoveIndex_management(fc, idxs)

As much as I provide the code above, I can't say I see the logic behind removing all attribute indexes for most or all feature classes in a geodatabase.

UPDATE:  I had to alter my original code because I forgot that Remove Index will fail if either the OID or shape index is passed to it, both of which are returned when getting a list of indexes.