Add Attribute Index (Data Management)

Summary

Adds an attribute index to an existing table, feature class, shapefile, coverage, or attributed relationship class.

Attribute indexes are used by ArcGIS to quickly locate records that match an attribute query. For information on attribute indexes in geodatabases, see Creating attribute indexes.

Usage

Syntax

AddIndex_management (in_table, fields, {index_name}, {unique}, {ascending})
ParameterExplanationData Type
in_table

The table containing the fields to be indexed.

Mosaic Layer; Raster Catalog Layer; Raster Layer; Table View
fields

The list of fields that will participate in the index. Any number of fields can be specified.

Field
index_name
(Optional)

The name of the new index. An index name is necessary when adding an index to geodatabase feature classes and tables. For other types of input, the Index Name is ignored

String
unique
(Optional)

Specifies whether the values in the index are unique.

  • NON_UNIQUEAll values in the index are not unique. This is the default.
  • UNIQUEAll values in the index are unique.
Boolean
ascending
(Optional)

Specifies whether values are indexed in ascending order.

  • NON_ASCENDINGValues are not indexed in ascending order. This is the default.
  • ASCENDINGValues are indexed in ascending order.
Boolean

Code Sample

AddIndex example 1 (stand-alone script)

The following stand-alone script demonstrates how to create an attribute index for specified fields.

# Name: AddAttIndex.py
# Description: Create an attribute Index for specified fields


# Import system modules
import arcpy
 
# Set a default workspace
arcpy.env.workspace = "c:/data"
  
try:
    # Create an attribute index for the few fields listed in command.
    arcpy.AddIndex_management ("counties.shp", "NAME;STATE_FIPS;CNTY_FIPS", "#", "NON_UNIQUE", "NON_ASCENDING")
    arcpy.AddIndex_management ("mexico.mdb/land/lakes", "NAME;geocompID", "NGIndex", "UNIQUE", "ASCENDING")
 
except Exception, e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message
AddIndex example 2 (Python window)

The following code demonstrates how to use the AddIndex function in a Python interactive window.

import arcpy
arcpy.env.workspace = "C:/data/input/indices.gdb"
arcpy.AddIndex_management("lakes", "NAME;geocompID", "NGIndex", "UNIQUE", "ASCENDING")

Environments

Related Topics

Licensing Information

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes

10/27/2014