Add Attribute Index (Data Management)

Summary

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

Attribute indexes are used by ArcGIS to quickly locate records that match an attribute query.

Usage

  • Shapefiles and file geodatabases do not support multiple indexes. Additional fields will become part of a composite index (that is, an index created on multiple fields in a table).

  • A new index is added for each unique index name in a geodatabase. If an index name already exists, it must be dropped before it can be updated.

  • For enterprise geodatabase data that is not registered as versioned, you can add both unique or nonunique indexes to GlobalID fields.

  • Unique and ascending indexes are not supported for shapefiles or file geodatabases. These parameters are ignored when the tool is run on a shapefile or on file geodatabase data.

Parameters

LabelExplanationData Type
Input Table

The table containing the fields to be indexed.

Mosaic Layer; Raster Layer; Table View
Fields to Index

The list of fields that will be indexed. 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 name is ignored.

String
Unique
(Optional)

Specifies whether the values in the index are unique.

  • Unchecked—No values in the index are unique. This is the default.
  • Checked—All values in the index are unique.

Boolean
Ascending
(Optional)

Specifies whether values will be indexed in ascending order.

  • Unchecked—Values will not be indexed in ascending order. This is the default.
  • Checked—Values will be indexed in ascending order.

Boolean

Derived Output

LabelExplanationData Type
Updated Input Table

The updated input table.

Table View; Raster Layer; Mosaic Layer

arcpy.management.AddIndex(in_table, fields, {index_name}, {unique}, {ascending})
NameExplanationData Type
in_table

The table containing the fields to be indexed.

Mosaic Layer; Raster Layer; Table View
fields
[fields,...]

The list of fields that will be indexed. 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 name is ignored.

String
unique
(Optional)

Specifies whether the values in the index are unique.

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

Specifies whether values will be indexed in ascending order.

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

Derived Output

NameExplanationData Type
out_table

The updated input table.

Table View; Raster Layer; Mosaic Layer

Code sample

AddIndex example 1 (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.sde"
arcpy.management.AddIndex("gdb.USER1.lakes", ["NAME", "geocompID"], "NGIndex", 
                          "UNIQUE", "ASCENDING")
AddIndex example 2 (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"

# Create an attribute index for the few fields listed in command.
arcpy.management.AddIndex("counties.shp", ["NAME", "STATE_FIPS", "CNTY_FIPS"], 
                          "#", "NON_UNIQUE", "NON_ASCENDING")
arcpy.management.AddIndex("mexico.gdb/land/lakes", ["NAME", "geocompID"], 
                          "NGIndex", "NON_UNIQUE", "NON_ASCENDING")

Environments

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics