ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

Add Attribute Index

  • Summary
  • Usage
  • Syntax
  • Code sample
  • Environments
  • Licensing information

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

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

  • Enterprise and file or personal geodatabases have a new index added for each unique index name. If an index name already exists, it must be dropped before it can be updated.

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

  • The Fields To Index parameter's Add Field button is used only in ModelBuilder. In ModelBuilder, where the preceding tool has not been run, or its derived data does not exist, the Fields To Index parameter may not be populated with field names. The Add Field button allows you to add expected fields so you can complete the Add Attribute Index dialog box and continue to build your model.

Syntax

arcpy.management.AddIndex(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
[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 name is ignored.

String
unique
(Optional)

Specifies whether the values in the index are unique.

  • NON_UNIQUE —All values in the index are not unique. This is the default.
  • UNIQUE —All values in the index are unique.
Boolean
ascending
(Optional)

Specifies whether values are indexed in ascending order.

  • NON_ASCENDING —Values are not indexed in ascending order. This is the default.
  • ASCENDING —Values are 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.AddIndex_management("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.AddIndex_management("counties.shp", ["NAME", "STATE_FIPS", "CNTY_FIPS"], "#", "NON_UNIQUE", "NON_ASCENDING")
arcpy.AddIndex_management("mexico.gdb/land/lakes", ["NAME", "geocompID"], "NGIndex", "NON_UNIQUE", "NON_ASCENDING")

Environments

  • Current Workspace

Licensing information

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

Related topics

  • An overview of the Indexes toolset

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2021 Esri. | Privacy | Legal